//解决Struts框架不支持中文数据的提交问题,过滤器
public class EncodingFilter implements Filter {
private String encoding;
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding=filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest request, ServletResponse response,FilterChain filterChain) {
try {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void destroy() {
}
}
web.xml中
<filter>
<filter-name>encoding</filter-name>
<filter-class>filters.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>