我写的一个过滤器, 在登录后可以正常使用, 但退出后直接访问页面地址的话, 第一次不经过过滤器, 哪位能够帮忙解决, 在线等
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletResponse servletResponse = (HttpServletResponse)response;
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
        Object userSession = null ; 
         try{
           userSession = httpServletRequest.getSession(true).getAttribute("user");
           System.out.println("session=="+userSession) ;
          if (userSession == null) {
             String path = httpServletRequest.getContextPath();
              servletResponse.sendRedirect(path+"/checkout.html");
           }else
           chain.doFilter(request, response);
            }catch(Exception e){
             e.printStackTrace() ;
            }
     }
这个是我的过滤器的部分代码
各位帮我看看有没有问题

解决方案 »

  1.   

    我觉得可能是web.xml里filter配置的问题比如说应该是*.*,而你却只写了*.jsp之类
      

  2.   

    你要判断一下是不是首页或是登录的action,如果是则允许通过就可以了。(总之不想验证的页面都要做个判断)
    http://blog.csdn.net/wpabbs/archive/2008/08/21/2806677.aspx
    部分代码:
      // 判断用户是否登录,如果没有,
      if (user == null || user.equals("")) {
       // 获锝当前的URL
       String strURL = sr.getRequestURL().toString();
       // 判断是否为index.jsp或userLogin.do
       if (strURL.indexOf("/index.jsp") == -1) {
              if (strURL.indexOf("/userLogin.do") == -1) {
    ......
      

  3.   

    在web.xml中,filter的mapping中对/*进行过滤
      

  4.   

    问题我已经找到, 可能是我表述的不太详细, 上述的那种情况只在退出后的窗口有效, 经过测试发现,是由于页面缓存导致的,所以我在页面上加了下面这句response.setHeader("Cache-Control","no-cache"); 这样问题就解决了, 希望能给有此疑惑的人一个提示, 谢谢各位的回答!