Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

refresh resubmits form

 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that processes an order and forwards (with the RequestDispatcher's forward() method) to either an error page jsp or order confirmation jsp. All of the code is working perfectly except for one thing -- if the user refreshes the page, the form data is re-submitted to the servlet. Is there any way to prevent this annoying behavior?

Thanks in advance.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make the JSP POST to a processing servlet, then use a sendRedirect to the confirmation page.
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that does work. I guess I avoided it because some JSP/Servlet books advise against using sendRedirect() in favor of forward() because the user won't see the page in the URL and can't bookmark it. I think the problem with a refresh resubmitting the form is a more serious problem than a user trying to bookmark the page.
 
Ginnakunta Laxmi Narayan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this. Place this code in .jsp file where the user enters order and press submit.

<%
//Invalidate cache code
response.addDateHeader("Expires", 1);
response.setHeader("Pragma","no-cache");

if (request.getProtocol().equals("HTTP/1.1")){
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
} else {
response.setHeader("Cache-Control", "no-cache");
}
%>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic