标签:java
/** * 统一设置字符集 */</span> public class CharsetEncodingFilter implements Filter { private String encoding; @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //System.out.println("CharsetEncodingFilter_____begin———————"); // 设置字符集</span> request.setCharacterEncoding(encoding); //继续执行</span> chain.doFilter(request, response); //System.out.println("CharsetEncodingFilter______end——————"); } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub encoding=filterConfig.getInitParameter("encoding"); } }
2)配置xml文件<filter> <!-- 配置实现Filter的类 --></span> <filter-name>CharsetEncodingFilter</filter-name> <filter-class>com.bjpowernode.drp.util.filter.CharsetEncodingFilter</filter-class> <!-- 设置初始化参数 --> </span> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <!-- 设置要拦截的url --></span> <filter-name>CharsetEncodingFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
标签:java
原文地址:http://blog.csdn.net/u010927139/article/details/46438821