These 2 articles talk about how to properly prevent idempotent data
from being manipulated (deleted, saved etc) more than once.

http://www.javaranch.com/journal/200603/frontman.html

http://www.theserverside.com/tt/articles/article.tss?l=RedirectAfterPost

I tested this on Tomcat 6.0.x, and found that regardless of which
method was used (GET or POST) , if an HTTP Forward (which returns
status code 200) was performed then the forms data was being saved
twice.


package test68.servlet;

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.IOException;

public class TestPostGetServlet extends HttpServlet {
   public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
       String testInputField = request.getParameter("testInputField");
       System.out.println("testInputField: " + testInputField);

       //rd.forward is HTTP Forward sends a 200ok status and retains
the original Http Request data.
       //In this case when the Refresh button is pressed on the
original JSP page, the form's data gets
       //RePOSTed
       //RequestDispatcher rd =
getServletContext().getRequestDispatcher("/p/test68/formMethodPost.jsp");
       //rd.forward(request,response);

       //response.sendRedirect is HTTP Redirect sends a 302
Temporarily Moved status and does not retain
       //the original Http Request data. In this case when the
Refresh button is pressed on the original
       //JSP page, the form's data doesn't get RePOSTed
       response.sendRedirect("/p/test68/formMethodPost.jsp");

   }

   public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
       String testInputField = request.getParameter("testInputField");
       System.out.println("testInputField: " + testInputField);

       //HTTP Forward and HTTP Redirect , behave in a similar manner
to doPost above.
       //RequestDispatcher rd =
getServletContext().getRequestDispatcher("/p/test68/formMethodGet.jsp");
       //rd.forward(request,response);
       response.sendRedirect("/p/test68/formMethodGet.jsp");
   }
}

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to