我正从LogoutServlet中的会话中删除一个属性。在另一个servlet(LogoutCheckServlet)中,我试图获得相同的属性,它仍然存在。请帮我找一下相同的原因。
LogoutServlet
公共类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();
}
}
}
LogoutCheckServlet
公共类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;
}
}
}