File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Page expired error when browser back button is hit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Page expired error when browser back button is hit" Watch "Page expired error when browser back button is hit" New topic
Author

Page expired error when browser back button is hit

Sripad Kumar
Greenhorn

Joined: Feb 26, 2005
Posts: 7
Hi,

I am developing few portal pages using JSP. I am facing some problems when HTML form is submitted and subsequently hit browser back button. I'm using POST to send the data to the server(I cannot use GET method instead of POST according to our requirement). I need to retain all the values entered in first page for subsequent search. I am handling through by storing all the values in Request object. But when I hit back button, I am getting "page expired" error.

Please provide me some work-around for this problem.

Thanks in advance.
Sripad.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The request object gets blown away with every new request, and anyway the "request object" actually only exists on the server, not the client. The page expired "error" isn't really an "error" per se, it's just an overblown way that most browsers say "the last update was in response to a POST - you really shouldn't be going back". Unfortunately, as long as you use a POST, you're going to see this message.

One way to continue to use POST, not see the message, and keep the last search parameters would be this approach - include the search form on the search results page so the user doesn't have to go back to get back to the form, it's just right there for them to use again if they need to, and when including the search form, have a way to set the values of your form to the current search values.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
sattithey
Greenhorn

Joined: Oct 22, 2008
Posts: 1
Hi,
i want to know is there any other way to handle the browser back button. If the user click on browser back button i want to send him to error page.
How can i do that.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by sattithey botla:
Hi,
i want to know is there any other way to handle the browser back button. If the user click on browser back button i want to send him to error page.
How can i do that.


You can do it using JavaScript. Otherwise, there is no way server can recognize whether the request is the result of a back button or the user posted the same URL again, deliberately.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi "sattithey" welcome to Javaranch ,
Please see your private messages for an important administrative matter.


SCJP, SCWCD.
|Asking Good Questions|
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by sattithey botla:
Hi,
i want to know is there any other way to handle the browser back button. If the user click on browser back button i want to send him to error page.
How can i do that.


you need to prevent browser cache and maintain session properly on every page......
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
you need to prevent browser cache and maintain session properly on every page......


"page expired" means browser is prevented from caching the page, I suppose. In fact it was a POST request.
[ October 22, 2008: Message edited by: Adeel Ansari ]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Adeel Ansari:


"page expired" means browser is prevented from caching the page, I suppose. In fact it was a POST request.

[ October 22, 2008: Message edited by: Adeel Ansari ]


HI Adeel Ansari,

you are right but,

i am suggesting to the sattithey botla's question . clearly i quoted .
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
Hi Adeel Ansari,

you are right but,

i am suggesting to the sattithey botla's question . clearly i quoted .


Even then its nothing to do with both, the browser cache and session, I believe.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Hello Sattithey,

Its not a good idea to hijack a thread. Please post your question in a new thread. It becomes quite confusing sometimes. Thanks.

BTW, your name became invalid, again.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Adeel Ansari:
Even then its nothing to do with both, the browser cache and session, I believe.

---------------------------------------------------------------------------
if you prevent browser cache and click the browser back button... the controll will go on server side .
------------------------------------------------------------------------

you believe me ? :p
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
if you prevent browser cache and click the browser back button... the controll will go on server side .

you believe me ?


And how then you distinguish, on the server-side, between the normal request and the request resulted from back button?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi,

hope This helps
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
hope This helps


I still didn't find the answer of my question in that thread, and my question remains. That thread is merely discussing how to prevent browser from caching.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Adeel Ansari:


And how then you distinguish, on the server-side, between the normal request and the request resulted from back button?


HI Adeel Ansari,


After pasting the above code in the jsps

when you click back button, browser understand that you want previous request to be done..so it will send the request ( in case of GET ,what you made in jsut previous request) to the server.. (request is request ..There is nothing called the normal request and request from back button)

Hope This Helps
[ October 22, 2008: Message edited by: seetharaman venkatasamy ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61318
    
  66

Originally posted by seetharaman venkatasamy:
After pasting the above code in the jsps

Rather than pasting the same code over and over again into JSPs (which be should be code-free in the first place) why not just do this in a filter?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
(request is request ..There is nothing called the normal request and request from back button)


Aha... Thats what I was expecting. .
Please refer to one of my previous post in this thread.

Originally posted by Adeel Ansari:
You can do it using JavaScript. Otherwise, there is no way server can recognize whether the request is the result of a back button or the user posted the same URL again, deliberately.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Bear Bibeault:
why not just do this in a filter?


Dear Bear,

Good suggestion. i know about filter,but i do not know how to use this concept in filter...

any idea or good url(link) to learn ?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
Good suggestion. i know about filter,but i do not know how to use this concept in filter...

any idea or good url(link) to learn ?


What you are doing is nothing, but modifying response headers. You can do it by configuring a filter, say invoke filter for every response.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

--------------------------------------------------
Originally posted by Adeel Ansari:

You can do it using JavaScript. Otherwise, there is no way server can recognize whether the request is the result of a back button or the user posted the same URL again, deliberately.
---------------------------------------------------------

correct .. so java script is only way? no. my point is using session also we can send him to the error page when he click on the browser back button
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by seetharaman venkatasamy:


i do not know how to use this concept in filter...

any idea or good url(link) to learn ?


Here is the link you asked for. Also take a look at this and this (a good one) .

Hope this helps
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

And I am getting a feeling that this thread is getting carried away and we are losing the original question.
So please no more posts on anything not related to the original post.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Amit
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
so java script is only way? no. my point is using session also we can send him to the error page when he click on the browser back button


That question of mine stands again.

And how then you exactly distinguish, on the server-side, between the normal request and the request resulted from back button?

As a matter of fact you need to know whether the request is the result of a back button or not, before re-directing the user to error page. And you said it yourself, "request is request there is nothing called the normal request and request from back button". That means we need to employ something, be it JavaScript, to know this fact.

I suppose, you are not really getting my point, and the whole discussion is going in vain.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30598
    
154

Originally posted by Adeel Ansari:
And how then you exactly distinguish, on the server-side, between the normal request and the request resulted from back button?

You could if you use a token. The first time that token is submitted is the initial request. Subsequent times are from the back button.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Jeanne Boyarsky:
You could if you use a token. The first time that token is submitted is the initial request. Subsequent times are from the back button.


Yeah why not. But not really, we can right click on the back button and choose how many steps we need to go back. This kind of tokens are just a workaround, in my opinion, unable to tell the exact thing. Furthermore, sometimes we ourselves make use of history.go(-1) function. One more thing, then you need to do is carefully consider the refresh attempts and count only back buttons. Hence, its better to do this stuff in JavaScript.

Nowdays, one can't imagine that the user would disable the JavaScript. Or if any user really practice this, you can ask user to enable JavaScript, in order to use the application. It will be a reasonable demand.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Adeel Ansari:
Hence, its better to do this stuff in JavaScript.



if yes, how you will do in javascript? what i feel is good session management is do the job well.

note: i expriment this scenario.

Hope This Helps
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
note: i expriment this scenario.


Ok, same question again. How did you manage to distinguish between a deliberate request from the user and a request made by pressing back button?

Even if you follow, Jeanne's suggestion you can't distinguish. All you get is a token telling you that its a request from back button, but its not a must. The user might have requested the URL in a normal way.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
if yes, how you will do in javascript?


Thats what I was waiting for. You can't really. It would be again a work-around . Choose what suits you best.

Hence, the reality is there is no foolproof method to do it, not even with the session management, nor JavaScript. As back button functionality can always be achieved by right clicking it, or by browsing browser's history.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Adeel Ansari:


Ok, same question again. How did you manage to distinguish between a deliberate request from the user and a request made by pressing back button?




why this?There is no need to know this.. once again and last i said you need to maintain session(ofcourse you need to do business logic) properly

Thanks
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by seetharaman venkatasamy:
why this?There is no need to know this.. once again and last i said you need to maintain session(ofcourse you need to do business logic) properly


Can you come up with something like Jeanne did? Instead of claiming same thign again and again without any single hint. Or You may leave it.
ayyappan Bas
Ranch Hand

Joined: Oct 11, 2008
Posts: 39
Originally posted by Sripad Kumar:
Hi,

I am developing few portal pages using JSP. I am facing some problems when HTML form is submitted and subsequently hit browser back button. I'm using POST to send the data to the server(I cannot use GET method instead of POST according to our requirement). I need to retain all the values entered in first page for subsequent search. I am handling through by storing all the values in Request object. But when I hit back button, I am getting "page expired" error.

Please provide me some work-around for this problem.

Thanks in advance.
Sripad.



its working.you do this .am using script.
<body onloa="backButtonOverride()">
function backButtonOverride(){
setTimeout("backButtonOverrideBody()", 0);}
function backButtonOverrideBody(){
try { history.forward(); } catch (e) {
} setTimeout("backButtonOverrideBody()", 500);
}</script>

Thanks in advance.
Ayyappan


Thanks & Regards
Ayyappan
 
GeeCON Prague 2014
 
subject: Page expired error when browser back button is hit