• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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");
}
%>
 
today's feeble attempt to support the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic