java为什么managedbean方法在post请求中的过滤器调用之前调用
我有一个过滤器,用来设置字符编码过滤器
网络。xml:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>ua.com.winforce.online.site.http.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
过滤器本身:
public class EncodingFilter implements Filter {
private static final String ENCODING = "UTF-8";
FilterConfig config;
public void init(FilterConfig filterConfig) throws ServletException {
this.config = filterConfig;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
request.setCharacterEncoding(ENCODING);
filterChain.doFilter(request, response);
}
public void destroy() {
}
}
一段标记用户提交表单:
<h:form>
<h:commandLink styleClass="ruski-button green-g full-width" action="#{supportController.save}" >
</h:commandLink>
</h:form>
问题是当post请求到来时,过滤器的方法doFilter
在supportController.save
方法之前调用。但是我需要在supportController.save
调用之前设置字符编码。我该怎么做
# 1 楼答案
更改过滤器映射
到