Filter转译编码问题之谜
//这个是过滤器的处理类
package filter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class filterconfig implements Filter{
protected String encoding=null;
protected FilterConfig config;
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
String encode=getEncoding();
if(encode!=null){
try {
request.setCharacterEncoding(encode);
} catch (UnsupportedEncodingException e) {
System.out.println("request.setCharacterEncoding(encode);出错了!");
e.printStackTrace();
}
System.out.println("------encode!=null-------"+encode);
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterconfig) throws ServletException {
// TODO Auto-generated method stub
this.config=filterconfig;
this.encoding=filterconfig.getInitParameter("Encoding");
}
public String getEncoding() {
return encoding;
}
public void setEncoding(String encoding) {
this.encoding = encoding;
}
}
//登陆表单
pageEncoding="GB2312"%>
Insert title here用户名
年 龄
//处理成功跳转页
pageEncoding="GB2312"%>
Insert title here你提交的内容是:
姓名:
年龄:
//web.xml配置文件
test
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
filter
filter.filterconfig
Encoding
GB2312
filter
/*
以上一切做完之后运行...得到的中文字符却没有正常显示.....