I have developed a simple web application using JSP. It has a login page which contains username, password fields and sumbit button. It has a logout page which contains a link to the login page. And there are some pages like page1, page2, page3, page4, etc.
Normal workflow is the following:
- After login comes page1.
- Then click some action and it will go to page2.
- Then click some action and it will go to page3.
- Then click some action and it will go to page4. So now I am in page4.
- Now click back button in navigation toolbar in browser, generally go to previous page (page3).
But my requirement is, if you click back button in navigation toolbar from any page in the application, then you should go to logout page. For example: if you are in page4 and press the back button, then you should go to logout page and not to page3.
How to achieve this? Is it anyway possible? Maybe with Javascript?
How can I trace and control the browser back button function in navigation tool-bar?
But my original requirement :
I have developed secured application using JSF framework.
And also i use scope (session scope)
In my application i use this following code ... but not work it...
public class **LogoutPhaseListener** implements **PhaseListener**
{
public void **afterPhase**(PhaseEvent event)
{
}
public void **beforePhase**(PhaseEvent event)
{
FacesContext facesContext = event.getFacesContext();
HttpServletResponse httpServletResponse = (HttpServletResponse) facesContext.getExternalContext().getResponse();
httpServletResponse.addHeader("Pragma", "no-cache");
httpServletResponse.addHeader("Cache-Control", "no-cache");
httpServletResponse.addHeader("Cache-Control", "must-revalidate");
httpServletResponse.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");
httpServletResponse.addHeader("Cache-Control", "no-store");
}
public PhaseId **getPhaseId**()
{
return PhaseId.RENDER_RESPONSE;
}
}
If i click back button in browser, then it go to previous page...
but i want to go logout page..when i click back button in browser...the above code not perfectly work it..