I have created webapplication using JSF 2.0 where I want to restrict user to go back after logout.
For solution I looked at Great BalusC answer and tried something else, however it is not working.
What I tried is as below.
<h:commandLink value="logout" action="#{bean.makeMeLogut()}" />
in bean I have
public void makeMeLogut() {
try {
// get response from JSF itself instead of coming from filter.
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("isLoggedIn", "false");
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
HttpServletResponse hsr = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
} catch (IOException ex) {
System.out.println("can't logut...");
}
}
As per BalusC answer, I need to create filter, however I thought to use JSF response and set header into it. However it is not working.
Any idea where I am going wrong?