关于过滤器网页编码问题

GamVan 2005-06-28 09:05:25
我写了个过滤器,把网页提交数据全部都用UTF编码转化了

但是我同时还把用户登录信息记录到了cookies

当关掉浏览器后,在进入我判断Session 不存在则从Cookies取出。。

但是cookies提交的时候由于过滤器作用已经是utf编码了

当我关掉浏览器再打开的时候从cookis提出来的数据肯定也是utf编码,

但是从新打开浏览器后过滤器又起作用,他把cookies又用utf编码了。

导致cookies经过两次utf编码提出来的中文数据都是问号 ?????

不知道哪位高手能解决一下这个问题。

附上过滤器代码不知道有没有用,,,容器是tomcat5

import java.io.IOException;
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 SetCharacterEncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;

public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignoer");
if(value==null)
this.ignore=true;
else if(value.equalsIgnoreCase("true"))
this.ignore=true;
else if(value.equalsIgnoreCase("yes"))
this.ignore=true;
else
this.ignore = false;

}


public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if(this.ignore||(request.getCharacterEncoding()==null)){
String encoding = selectEncoding(request);
if(encoding!=null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request,response);

}

public void destroy() {
this.encoding = null;
this.filterConfig = null;

}
protected String selectEncoding(ServletRequest request) {
return this.encoding;
}
}





...全文
76 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧