aspose file tools*
The moose likes Servlets and the fly likes refresh resubmits form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "refresh resubmits form" Watch "refresh resubmits form" New topic
Author

refresh resubmits form

M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
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

Joined: Mar 06, 2001
Posts: 13459

Make the JSP POST to a processing servlet, then use a sendRedirect to the confirmation page.
M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
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

Joined: Jun 16, 2004
Posts: 35
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: refresh resubmits form