码迷,mamicode.com
首页 > 其他好文 > 详细

过滤器--过滤编码

时间:2014-10-23 14:11:30      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   ar   sp   div   on   

  • 在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 }

     

过滤器--过滤编码

标签:des   style   blog   color   io   ar   sp   div   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!