views:

44

answers:

3

I'm working on a web application using JSP/Servlets, etc. And I have a lot of form progression. I am aware of some ways to use the "Back" functionality, but I am not sure if its efficient enough.

What are the best ways to implement this? Does it Involve using the session object? or just the request? or neither?

+1  A: 

If you don't have any particular reason, why don't you use javascript to do this?

<FORM> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"> </FORM>

You can refer to some other ways to do it in javascript: http://www.comptechdoc.org/independent/web/cgi/javamanual/javahistory.html

The reason it's cool is that you don't have to handle this piece of "back" code in your server. You let browsers handle it for you.

If you insist in doing so in plain java, I think session is the best way to do it. If you would like to remember the whole path, all you have to do it to store an Stack in your session, and name it history or something alike. You pop out one URL whenever the user click back, and push an URL when the user click into a new URL.

Winston Chen
This Javascript is not unobtrusive. I recommend to do so in the server side and use JS only as progressive enhancement.
BalusC
+1  A: 

Well it depends on your needs really, however I would go with sessions, e.g:

  • If you don't want somebody to click back, expire the session.
  • If you want somebody to go back, keep the session going with the needed vars

The session will make it the easiest in my views, as well as the most robust.

Kyle Rozendo
A: 
<FORM> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"> </FORM>

This is a way to accomplish it, but this may or may not preserve your form values. The bigger risk associated with this is form resubmission. Say you have a screen where you are submitting and a credit card is being billed. If you go back this way, the form will resubmit and the user will be billed again.

The better way to implement back however is to have another action altogether. Repopulate all your Form values in this action and forward to the previous JSP.

Vaishak Suresh