0

Please advise how can I refresh a jsp page on a browser back button click.

I saw a lot of questions , articles on this but nothing helped me. Tried pointers from these questions -

How to control web page caching, across all browsers? ,
Add an Expires or a Cache-Control header in JSP

but may be these links are pretty old and on latest browsers there is some other way to refresh a jsp page on browser back button? please advise.

Thanks for your help!

Update -

I should have added the details of what I am trying to achieve - I have 1st Page (jsp) which is having a form (update / close your ticket). On submission of that form i show 2nd page (jsp) which contains "thank you message!". From page 2 if user hits browser back button it again takes me to 1st page. I want to refresh the page 1 on a back button click from page 2, so that if user updated/ closed the ticket initially , I display the refreshed page 1 to avoid the unwanted actions.

Please advise how can I refresh a jsp page on a browser back button click.

Community
  • 1
  • 1
dev123
  • 335
  • 1
  • 6
  • 13

1 Answers1

0

Always use response.sendRedirect(...); return; at the end of any JSP/servlet that does anything that updates the server, and then don't worry about the back button.

developerwjk
  • 8,335
  • 2
  • 11
  • 31
  • Actually I need to refresh the jsp page 1 on back button click from page 2 , to display the most current data. Updated the question. – dev123 Mar 03 '14 at 23:43
  • Give the user a link back to the main page so they don't click the back button. – developerwjk Mar 03 '14 at 23:45
  • I provide that (link on page 2 to the main mapge) , but they can still click back button and I want to refresh the page 1 if they do so. is there a way? – dev123 Mar 03 '14 at 23:49
  • Or make the page redirect on the client side in 1 sec to the main page. Typically not even the javascript onload function fires reliably when you get to the page from the back button. Only way to solve your problem is train the users to not use it, or entice them away from using it. – developerwjk Mar 03 '14 at 23:50
  • Or use Ajax. Send your ticket creation request with Ajax, show a little Div Popup that says thanks, make that Div fade away after a sec. Thus you never leave the first page, then use javascript to make the page refresh using another ajax request. – developerwjk Mar 03 '14 at 23:52