servlet web.xml 中文乱码

 
  
过滤器代码(本人家里没环境 复制别人的过滤器改的 如果有错的话你就自己改下波。。)
Java code
 ------ import java.io.IOException; import javax.servlet. * ; public class EncodingFilter implements Filter {    FilterConfig config;    public void setFilterConfig(FilterConfig config) {    this .config = config;    }    public FilterConfig getFilterConfig() {    return config;    }    public void doFilter(ServletRequest r1, ServletResponse r2, FilterChain chain) { HttpServletRequest request = (HttpServletRequest)r1; HttpServletResponse response = (HttpServletResponse)r2; String encoding = " UTF-8 " ; request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); chain.doFilter(r1, r2);    }   }


web.xml配置

XML code
 
  
< filter > < filter-name > EncodingFilter filter-name > < filter-class > 过滤器的位置 filter-class > filter > < filter-mapping > < filter-name > EncodingFilter filter-name > < url-pattern > /* url-pattern > filter-mapping >



你可能感兴趣的:(工作问题)