0

我正在从我的 LogoutServlet 中的会话中删除一个属性。在另一个 servlet(LogoutCheckServlet) 中,我试图获得相同的属性,但它仍然存在。请帮我找出同样的原因。

注销Servlet

公共类 LogoutServlet 扩展 HttpServlet {

/**
 * 
 */
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) {

    HttpSession session= request.getSession(false);
    if(session.getAttribute("userInfo")!=null) { 
        System.out.println("In Logout");
        session.removeAttribute("userInfo");
        session.invalidate();
        System.out.println("In Logout");
    }
    try {
        response.sendRedirect("http://localhost:8080/loginpoc/JSP/Login.jsp");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



}

}

注销CheckServlet

公共类 SessionCheck 扩展 HttpServlet {

/**
 * 
 */
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    resp.setContentType("text/xml");
    String response=null;
    UserSessionInfoBean bean=null;
    try {
        System.out.println("In Session Check");
        HttpSession session= req.getSession(false);
        /*
        if (session.isNew()){
            System.out.println("New");
            System.out.println("New Session Id:"+session.getId());
            System.out.println("New Creation Time:- "+session.getCreationTime());
        }
        else{
            System.out.println("Old");
            System.out.println("Else Session Id:"+session.getId());
            System.out.println("Else Creation Time:- "+session.getCreationTime());
        }*/
        bean=(UserSessionInfoBean)session.getAttribute("userInfo");
        System.out.println(bean.getFullName());
        if (bean.getFullName()==null){
            response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>N</root>";
            System.out.println("If block");
        }   
         else{
            response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>Y</root>";
            System.out.println("Else block");
         }
        resp.getWriter().println(response);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally{
        bean=null;
    }
}

}

4

0 回答 0