File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Request Dispatcher forward and the back button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatcher forward and the back button" Watch "Request Dispatcher forward and the back button" New topic

Request Dispatcher forward and the back button

Anand Athinarayanan
Ranch Hand

Joined: May 20, 2011
Posts: 30

I have a question regarding the forward method of request dispatcher. I know the difference between forward and sendredirect but what i'm not able to understand is why the browser behaves quirky when i click on back button. So here is what I have.

1. A page foo.jsp is displayed to the user which has links and a text box and a submit button. The form action is / (Yes its struts but my question is not related to struts).Its a post request.
2. If the user clicks on the link (form is submitted thro javascript) or the submit button the request is sent to the server and the controller after processing forwards the request to bar.jsp.

Now bar.jsp is displayed and my address bar is still at / which is correct since its a server side forward. Now when I click on back button in bar.jsp nothing is happening, the same page (bar.jsp) is displayed again, i can't even say its loaded again because the page is not refreshed, its just like the back button is not working and its not sending any request to the server because I monitor the server after clicking on the back button and there are no activity. I don't have cache prevention headers in my response, so I'm assuming the browser has cached bar.jsp and foo.jsp but why is not going back to foo.jsp when i click on back button ?

Second question -> While in bar.jsp if i press F5 i get a pop up saying the information must be resubmitted, now I'm confused if the page is cached why is it requesting the server again ?

Third question --> Will browsers cache post requests by default if we don't have cache control headers in the response ?

I tested in IE 6 and FF 3.

Thanks !
I agree. Here's the link:
subject: Request Dispatcher forward and the back button
It's not a secret anymore!