首页 > 其他 > 详细

过滤器--过滤编码

时间:2014-10-23 14:08:41      阅读:218      评论:0      收藏:0      [点我收藏+]
  • 在servlet3.0中可以在页面配置
     1 @WebFilter(
     2         filterName= "encodingFilter" , 
     3         urlPatterns = {"/*"} , 
     4         initParams = { @WebInitParam(name ="encoding" , value= "utf-8")} ,
     5         asyncSupported = true
     6         )
     7 public class EncodingFilter implements Filter{
     8     private String encoding = null;
     9     @Override
    10     public void destroy() {
    11         
    12         
    13     }
    14 
    15     @Override
    16     public void doFilter(ServletRequest request, ServletResponse response,
    17             FilterChain chain) throws IOException, ServletException {
    18         request.setCharacterEncoding(encoding);
    19         response.setCharacterEncoding(encoding);
    20         response.setContentType("text/html");
    21         chain.doFilter(request, response);
    22     }
    23 
    24     @Override
    25     public void init(FilterConfig config) throws ServletException {
    26         encoding = config.getInitParameter("encoding");
    27         System.out.println("过滤字符编码");
    28     }
    29 
    30 }

     

过滤器--过滤编码

原文:http://www.cnblogs.com/dashen/p/4045404.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!