filter为什么不起作用?
我写了一个filter来过滤JSP页面的中文编码问题
单步调试的时候程序已经跳入filter了;但JSP页面上的中文数据传入BEAN的时候还是出现乱码问题;
我的JSP页面上设置了文件头:
<%@page contentType= "text/html; charset=GBK "%>
也面上的中文是正常显示的,就是在传值的时候出现乱码
我的filter代码如下:
package com.wmf.struts;
//Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
//Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
//Decompiler options: packimports(3) fieldsfirst ansi
//Source File Name: Unknown Source
import
java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
public class servfilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
try {
response.setCharacterEncoding( "GBK ");
request.setCharacterEncoding( "GBK ");
response.setContentType( "text/html; charset=GBK ");
((HttpServletResponse)response).setHeader( "Pragma ", "No-cache ");
((HttpServletResponse)response).setHeader( "Cache-Control ", "no-cache ");
((HttpServletResponse)response).setHeader( "Expires ", "0 ");
filterChain.doFilter(request, response);
}
catch(
ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(
IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
//Clean up resources
public void destroy() {
}
}
web.xml里面的配置如下:
<filter>
<filter-name> servfilter </filter-name>
<filter-class> com.wmf.struts.servfilter </filter-class>
<init-param>