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

FIlter应用

时间:2016-04-26 19:04:17      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

浏览器不缓存页面的过滤器

System.out.println("cacheFilterDO");
        response.setDateHeader("Expires", -1);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        chain.doFilter(request, response);

解决中文乱码的过滤器Filter

 

<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.sdut.util.cn.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>

public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");        
    }
    
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);//解决中文问题
        chain.doFilter(request, response);        
    }

 

FIlter应用

标签:

原文地址:http://www.cnblogs.com/wlc297984368/p/5435893.html

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