This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes disable the back button in webapplication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "disable the back button in webapplication" Watch "disable the back button in webapplication" New topic
Author

disable the back button in webapplication

sandy indira
Greenhorn

Joined: Feb 03, 2010
Posts: 13
disable the back button in webapplication


after logout the user is sent back to the login page and there if he press the back button the request should go to the controller(server) and
check whether is he properly logged in if yes allow him other wise display the login page...


help guys give me some nice code or some good suggestions for this...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Generally browsers store pages in their cache and when you press the back button, the browser displays the page from its cache. To make the browser request the page again from the server (so that you can check whether the user is logged in or not), you'll have to put some headers in the pages which you only want to be visible after user is logged in. Read this to know which headers to use...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

sandy indiranagar wrote:

Like I had requested you before here you really need to check your private messages and take appropriate action. Please note this is not optional.

It is expected you take the required action, before you post again.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
sandy indira
Greenhorn

Joined: Feb 03, 2010
Posts: 13
friend i dont want to disable the back button instead i want to create a check on user..

after logout if he press the back button the request should go to the controller and check is he a valid user if yes
allow him or if not redirect him to the login page...


and i saw the private message there were no new messhages...plss i have seen the naming convention..even if needed i can again change just tell me if needed...
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Check again
sandy indira
Greenhorn

Joined: Feb 03, 2010
Posts: 13
friends i tried all these but it didnt help..

it still caching the data...i.e the name if the user and allowing him to come back to the home page after logout by pressing back button...

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
<meta http-equiv="expires" content=<%= new java.util.Date() %>>
<meta http-equiv="no-cache">
<script type="text/javascript"></script>
</head>
<body>

<% response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
response.setHeader("Cache-Control","no-store"); //HTTP 1.1 %>



<--body of my page----->

</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Sandy please restrict talk about one problem to one thread, don't post the same problem multiple times like here or here...
Ronnie Reed
Greenhorn

Joined: Feb 19, 2010
Posts: 2
Sandy , which framework are you using . Spring implicitly handles this because each request madatorily hits the controller before the JSP is invoked. If you are using Struts you might have to write an Ajax call on the "onPageLoad" of the previous page which the control would go on hitting back and then send the request to a different class where you can perform some logic.

Hope this helps.
 
GeeCON Prague 2014
 
subject: disable the back button in webapplication