• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

refresh resubmits form

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
%>
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic