Tuesday, 7 May 2013

How to terminate the session? | JSF Interview Questions

In order to terminate the session you can use session invalidate method.
This is an example how to terminate the session from the action method of a backing bean:
public String logout() {
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
session.invalidate();
return "login_page";
}

The following code snippet allows to terminate the session from the jsp page:
<% session.invalidate(); %> <c:redirect url="loginPage.jsf" />

No comments: