ITPub博客

首页 > 应用开发 > IT综合 > 今日完善了字符编码过滤器。

今日完善了字符编码过滤器。

原创 IT综合 作者:gyang 时间:2009-01-20 14:00:34 0 删除 编辑

public class CharacterEncodingFilter implements Filter {

private String encoding = "utf-8";

private String serverEncodingForGet = "ISO8859_1";

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) req;
final HttpServletResponse response = (HttpServletResponse) res;
//System.out.println(request.getContextPath()+":"+request.getServletPath());
//System.out.println(request.getMethod());
if (request.getMethod().equalsIgnoreCase("GET")) {
request = new RequestWrapper(request, serverEncodingForGet, encoding);
//System.out.println("new encoding filter :get");
} else {
// 处理post参数
request.setCharacterEncoding(encoding);
// 处理post中混合的get参数
request = new MixedRequestWrapper(request, serverEncodingForGet,encoding);
//System.out.println("new encoding filter :post");
}
// 下面语句在frameset实现跨域访问,解决frameset中cookie、session丢失问题
//((HttpServletResponse)response).setHeader("P3P","CP=CAO PSA OUR");
chain.doFilter(request, response);
}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15247/viewspace-1016339/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-09-18

  • 博文量
    32
  • 访问量
    89167