Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Back button behaviour

 
Gezza Hall
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks!
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sunesh Kumar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.

Bye..
 
Gezza Hall
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic