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

RequestDispatcher refresh problems!

bob dapaah
Ranch Hand

Joined: Jan 15, 2002
Posts: 46
I have the following scenario:
JSP page A sends a GET request to a Servlet. The Servlet carries out an operation on a database then creates a RequestDispatcher to forward() the response to JSP page B for display.
The problem arises when page B is refreshed. The initial request is repeated which is not always favourable (e.g. if the request was intended to delete the last message etc).
Is this standard behaviour for the RequestDispatcher? If so is there any way to control this feature so that "once-only" operations are not repeated?
I'd be grateful for any help as none of the literature I've read is clear on this point.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

There are other things which complicate this, but in situations where a page is the result of POSTed data (as it should be, but I guess GET works too), I prefer to use response.sendRedirect rather than including or forwarding to the next page.
This changes the url shown in the client browser, so that they request the display page rather than resubmitting data when they refresh the browser window.
I agree. Here's the link:
subject: RequestDispatcher refresh problems!
jQuery in Action, 3rd edition