wood burning stoves 2.0*
The moose likes JSP and the fly likes Problem caused by pressing the 'BACK' button on the broswer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem caused by pressing the Watch "Problem caused by pressing the New topic
Author

Problem caused by pressing the 'BACK' button on the broswer

chiu pong
Greenhorn

Joined: Aug 11, 2003
Posts: 11
hi,
I have a question about the problem caused by pressing the 'BACK' button on the broswer.
Suppose i have 3 pages, namely a.jsp, b.jsp and c.jsp.
a.jsp contains a form for user to enter some information and its action page is b.jsp.
b.jsp will collect the information from a.jsp and insert it to the database and then redirect to c.jsp.
c.jsp is just a notice page. However if the user press the 'BACK' button on c.jsp, it will cause the b.jsp to insert the data again.
So how can i handle this situation? Is it an usual way to set a session in a.jsp and invalidate it at the end of b.jsp?
thx for reply.
cheers,
ypc
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I never do it this way. Firstly yu have to use the MVC (Model, View, Controller architecture)
There are two Controllers, A and C (following your naming)
The user requests 'A' via a 'GET' request, they are shown the view 'a.jsp'. 'a.jsp' POSTs back to A.
Back in 'A', it resonds to the POST by processing the request and using sendRedirect() to 'C'. 'C' responds to the GET request by showing the view 'c.jsp'.
If the user hits the back button, it skips the POST since there is no view and goes back to the GET 'A' request. The data is not resubmitted.
Try this at home
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem caused by pressing the 'BACK' button on the broswer
 
Similar Threads
Changing the URL when using forward or redirect...
jsp:include
page relative vs file relative [ include action vs include directive]
Relative URL specifications, JSP 1.2.1
How to keep values from calling multiple jsp