How to make the log off button working in java ?
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
public String logoff() {
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) ectx.getSession(false);
session.invalidate();
return "index?faces-redirect=true";
}
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) ectx.getSession(false);
session.invalidate();
return "index?faces-redirect=true";
}
// using the method with command button of primefaces
<p:commandButton type="submit" icon="ui-icon-power" value="Log-off" immediate="true"
action="#{user.logoff()}" ajax="false"/>
No comments:
Post a Comment