Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher refresh problems!

 
bob dapaah
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic