wood burning stoves
The moose likes JSP and the fly likes Back button behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Back button behaviour" Watch "Back button behaviour" New topic

Back button behaviour

Gezza Hall
Ranch Hand

Joined: Jan 04, 2005
Posts: 33
Hi all,

I have a jsp/struts application. I want to ensure that after my form has been submitted (hence calling the struts form class which validates the form values) if the user clicks the back button, the form is displayed exactly as it was with all the values intact.

Note this is not a struts problem - the form fields are standard html notation, not struts. I simply want to ensure that the user can press 'back' without the page executing again - maybe some kind of caching thing?

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

I simply want to ensure that the user can press 'back' without the page executing again

You can't do that from server side code. Try with Javascript.

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Sunesh Kumar
Ranch Hand

Joined: Oct 17, 2005
Posts: 89

I go with vishnu.

First store all the values in javascript if the form is filled or else keep them as default values.
If the body is painted again then get the values from Javascript to feilds again.


Thanks & Regards<br />Sunesh Kumar Baachu
Gezza Hall
Ranch Hand

Joined: Jan 04, 2005
Posts: 33
No, I'm not using javascript in that sense, goes against the whole purpose of using jsp and struts!

But in this instance, I do use some javascript. I use the...

<a href="javascript: history.go(-1)">Back</a>

...to get back to the original page.
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hey hi ,

Who said you need to use JS for that small thingy ?? Definately , There are 2 approaches for this... One thing is this small code

response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Pragma" content="no-cache">

Also there as its a Struts / JSP App , You can use a design pattern called Synchronization Token for it.. You can get details on it here..

Java World

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
I agree. Here's the link: http://aspose.com/file-tools
subject: Back button behaviour
It's not a secret anymore!