五种基本的过滤器

参考地址:http://www.verydemo.com/demo_c134_i24427.html

 

一、使浏览器不缓存页面的过滤器    

import javax.servlet.*;    
import javax.servlet.http.HttpServletResponse;    
import java.io.IOException;    
   
/** 
* 用于的使 Browser 不缓存页面的过滤器 
*/   
public class ForceNoCacheFilter implements Filter {    
   
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException    
{    
    ((HttpServletResponse) response).setHeader("Cache-Control","no-cache");    
    ((HttpServletResponse) response).setHeader("Pragma","no-cache");    
    ((HttpServletResponse) response).setDateHeader ("Expires", -1);    
    filterChain.doFilter(request, response);    
}    
   
public void destroy()    
{    
}    
   
     public void init(FilterConfig filterConfig) throws ServletException    
{    
}    
}    


  
二、检测用户是否登陆的过滤器    
   

import javax.servlet.*;    
import javax.servlet.http.HttpServletRequest;    
import javax.servlet.http.HttpServletResponse;    
import javax.servlet.http.HttpSession;    
import java.util.List;    
import java.util.ArrayList;    
import java.util.StringTokenizer;    
import java.io.IOException;    
  …………………………………………………………………………

你可能感兴趣的:(过滤器)