Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
Author

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.
Thanks
Bob
David O'Meara
Rancher

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.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher refresh problems!
 
Similar Threads
Servlet URL repeating
ServletRequest RequestDispatcher
How can I get correct backto page?
Using sendRedirect and requestDispatcher
Accessing scoped variables using EL