Results 1 to 4 of 4

Thread: Duplicate Form Submission

  1. #1
    Join Date
    Nov 2004
    Posts
    2

    Default Duplicate Form Submission

    Hi ,

    I have been trying to disable duplicate form submission in the application that I am working on. I followed the JavaDoc on AbstractFormController.handleInvalidSubmit() and had the method handleInvalidSubmit() overridden in the subclass to return to an error page.
    Also the form used for this controller is a session form. However after submitting the form, I can still resubmit it by going back and clicking submit.

    I thought all I needed to do was override the handleInvalidSubmit() method in the subclass and have the form as sessionForm. Pls also note that I have not overridden formBackingObject(), hence it never returns a preinitialized backing object (but should this matter ?).

    When I tried to debug, I notice that handleInvalidSubmit() never gets called. So I guess in AbstractFormController.handleRequestInternal(),
    if (isSessionForm() && request.getSession().getAttribute(getFormSessionAt tributeName()) == null) {
    // cannot submit a session form if no form object is in the session
    return handleInvalidSubmit(request, response);
    }
    the condition is never true.

    Could someone please help me out ?

    Thanks a lot in advance.

    Arun chalise

  2. #2
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    The 'session form' way sets the command in the session when the form is shown (which includes form reshowing when validation failed) and remove it when the command is read.
    Could you set a breakpoint on the getCommand(HttpServletRequest) method to see what happens? It is normally called in the handleRequestInternal method just after the check for invalid submission you quoted.

    Olivier

  3. #3
    Join Date
    Nov 2004
    Posts
    2

    Default

    I realized that i had put

    response.setHeader("Cache-Control","no-store"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0

    in the page that i was trying to test duplicate form submission.
    And realized that everytime I hit back to return to the page, the getFormSessionAttributeName()) == null condition failed as it was not using 'cache' and was always issuing request to the server in whichcase showForm would be called and the session attribute name for the form would be set.

    Once I set the response headers to not use cache, it all works fine.

    Thanks
    arun

  4. #4

    Default

    prevent duplicate submit
    Code:
     protected ModelAndView disallowDuplicateFormSubmission(HttpServletRequest
            request, HttpServletResponse response) throws Exception
        {
            BindException errors = new BindException(formBackingObject(request),
                                                     getCommandName());
            errors.reject("duplicateFormSubmission", "Duplicate form submission");
            return showForm(request, response, errors);
        }

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Duplicate Form Submission Handling
    By franksegust in forum Web
    Replies: 6
    Last Post: May 5th, 2006, 11:24 AM
  3. Replies: 9
    Last Post: May 4th, 2006, 09:53 AM
  4. Replies: 5
    Last Post: Aug 5th, 2005, 06:29 AM
  5. Submission of empty form fields
    By steven.warren in forum Web
    Replies: 7
    Last Post: Aug 17th, 2004, 03:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •