File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem caused by pressing the Watch "Problem caused by pressing the New topic

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

chiu pong

Joined: Aug 11, 2003
Posts: 11
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.
David O'Meara

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
I agree. Here's the link:
subject: Problem caused by pressing the 'BACK' button on the broswer
It's not a secret anymore!