my dog learned polymorphism*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatcher forward and the back button" Watch "Request Dispatcher forward and the back button" New topic
Author

Request Dispatcher forward and the back button

Anand Athinarayanan
Greenhorn

Joined: May 20, 2011
Posts: 27
All,

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 /foo.do (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 /foo.do 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: http://aspose.com/file-tools
 
subject: Request Dispatcher forward and the back button
 
Similar Threads
How do i use requestDispatcher.forward to forward to my struts action servlet?
Question about back button in browser
Browser back/forward problem
browser back button problem.
Getting confuse on Struts action call when I click back button