第二次请求不起作用

时间:2013-07-11 11:31:00

标签: java http networking

我使用会话和过滤器做一个java web项目。在我的代码中第二次请求转发请求不起作用。谁能告诉我为什么?

这里是我的代码FilterRequest.java代码

public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
      try{
          HttpServletRequest request = (HttpServletRequest) req;
          HttpServletResponse response = (HttpServletResponse) resp;
          //System.out.println("Inside the filter.............."  );
          HttpSession session = request.getSession(true);
          User u = null;
          if(session.getAttribute("loggedUser")!=null){
              u = (User) session.getAttribute("loggedUser");
          }       
          if (u!= null || session.getAttribute("loggedUser")!=null)
          {
              //System.out.println("user does exits.." + u.getUname() );
              chain.doFilter(req, resp);          
          }else{              
              //System.out.println("user does not exits..");
              String message = "Please Login!";             
              request.setAttribute("loginMsg", message);
              response.sendRedirect(request.getContextPath() + "/login2.jsp?loginMsg=");    
              //response.sendRedirect("login2.jsp"); // infine loop occures
          }
      }catch(Exception e){
          e.printStackTrace();
      }
    }

0 个答案:

没有答案