建立文件继承filter接口如下
package orgwkjzfxfileEncoding;
import javaioIOException;
import javaxservletFilter;
import javaxservletFilterChain;
import javaxservletFilterConfig;
import javaxservletServletException;
import javaxservletServletRequest;
import javaxservletServletResponse;
public class Encoding implements Filter {
public void destroy() {
}
/**
* 中文乱码处理
* */
public void doFilter(ServletRequest arg ServletResponse arg
FilterChain arg) throws IOException ServletException {
argsetCharacterEncoding(GBK);
argsetCharacterEncoding(GBK);
argdoFilter(arg arg);
}
public void init(FilterConfig arg) throws ServletException {
// TODO Autogenerated method stub
}
}
然后在webxml里面配置如下
<filter>
<filtername>Encoding</filtername>
<filterclass>orgwkjzfxfileEncodingEncoding</filterclass>
</filter>
<filtermapping>
<filtername>Encoding</filtername>
<urlpattern>/*</urlpattern>
</filtermapping>
试试ok!了