A pretty simple requirement. After logging into web J2EE 6 application, how can I have the user logout again?
Most (all?) the books and tutorials I have seen show h
Two step process -
1.create the logout page
2.create a session bean with a logout method
STEP A: The Logout Page
Hello #{userSession.username},
STEP B: Session Bean Backing Code (snippet)
public String logout() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
session.invalidate();
return "/index?faces-redirect=true";
}
public boolean isUserLoggedIn() {
String user = this.getUsername();
boolean result = !((user == null)|| user.isEmpty());
return result;
}
/** Get the login username if it exists */
public String getUsername() {
String user = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
return user;
}