Jsp 会话注销时出现问题

Jsp 会话注销时出现问题,jsp,session,servlets,session-variables,sessiontracking,Jsp,Session,Servlets,Session Variables,Sessiontracking,我已经读到,我们可以在servlet中使用logout()方法。 所以,我在做这样的事情 HttpSession sr=request.getSession(); sr.logout(); 但是这给了我一个错误,它找不到logout()符号; Plz帮助。我希望用户注销并转到主页(home.jsp)。HttpSession中不存在注销方法 //This code will redirect to homepage.jsp RequestDispatcher rd = request.get

我已经读到,我们可以在servlet中使用logout()方法。 所以,我在做这样的事情

HttpSession sr=request.getSession();
sr.logout();
但是这给了我一个错误,它找不到logout()符号;
Plz帮助。我希望用户注销并转到主页(home.jsp)。

HttpSession中不存在注销方法

//This code will redirect to  homepage.jsp
 RequestDispatcher rd = request.getRequestDispatcher("homepage.jsp");
  rd.forward(request, response);

您可以使用
session.invalidate()
使会话无效

HttpServletRequest
有一个方法,但它假定您使用servlet方式来实现安全性。它会清除安全上下文,但不会清除会话

如果您只想清除会话,请执行以下操作

HttpSession sr = request.getSession();
sr.invalidate();

@saumyaraj是的,它将删除会话中的所有内容(属性..等)。