• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to invoke a method when back button in browser is clicked.

 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I wanted to know how can we make it possible so that if a user clicks on the back button on the browser he should be redirected/forwarded to an error page or may be a session expired page (if he uses back after signing out)?
-Regards
Prakash
[ October 15, 2007: Message edited by: prakashSchauhan ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"prakashSchauhan", please check your private messages for an important message from me.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to prevent caching on client browser.

You can use this code to do that

 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Anmol Thanks for the quick reply.

-Regards
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on which page do we have to do the disabling of the Cache?
if the flow is from A.jsp->B.jsp then on which page do i need to write that code? B.jsp?
-Thanks.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The page which you dont want to cache, since you dont want to come to a.jsp on click of the back button without sending a new request to server, you need set these headers with the response of a.jsp.
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay what i have here is AddEmployee.jsp , its submit button invokes a servlet which forwards (Requestdispatcher) to another Result.jsp page.
I initially added the code you sent to the AddEmployeeServlet which made my Result.jsp page "cache-Disabled" i can not go back to the Result page but i could still go back to the AddEmployee.jsp page.
Then i added the same code in my AddEmplyee.jsp (as scriplet ) but still i am not able to make my addEmployee.jsp page "cached-disabled" ,
is the intermediate Sevlet causing any problem?

-Thanks.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code as well explaining what you tried? post the two jsps and the servlet. It would be much easy to help you out. Its important where you are setting those headers in the jsp, it should not be done once response is committed.
Also you need to follow a naming convention here on javaranch, did you check the private message from Bear?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"prakashSchauhan",
It is important that you check your private messages and follow the instructions given by Bear Bibeault.

Thank you
-Ben
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, please check your private messages again.
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code for first page:
--------------------------

--------------------------

After this i have a servlet , which just takes up the parametes and adds it to the database and then goes to the next Result page
-----------------------------------------------------------------------
this is the servlet code:


______________________________________________________________________
This is result.jsp


----------------------------------------------------
Wht is wrong here?
-Thanks


[BSouther: Added UBB CODE tags]
[ October 18, 2007: Message edited by: Ben Souther ]
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any suggestions??
-Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server has no way of knowing if a request was triggered by the back button.

Look into the Post-Redirect-Get pattern to help with this problem.
There is an example in our JSP FAQ page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!