Announcement Announcement Module
Collapse
No announcement yet.
Duplicate Form Submission Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicate Form Submission

    Hi All,

    How to identify the duplicate form submission in Spring MVC?

    The problem I am facing is, the user is displayed a form. When the user enters the values and submits the form, I insert the values and show the user the same page (form) saying the successful submission. When the Page is refreshed, the datas are again populated with the values. I cannot redirect the user to different page. I need to show the same page.

    I have used a SimpleFormController.

    Code:
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    {
          //Insert in to DB
          //Populate the Model and send the view.
          ModelAndView successModelAndView = new ModelAndView(getFormView());
          successModelAndView.addObject("message", "successful.insertion");
          return successModelAndView;
    }
    For Identifying the Duplicate Form Submission. I have used.

    Code:
    protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response)throws Exception
    {
    BindException errors = getErrorsForNewForm(request);
    errors.reject("duplicateFormSubmission", "Duplicate form submission");
    return showForm(request, response, errors);
    }
    In servlet.xml file I have configured for this controller as:

    Code:
    <property name="sessionForm"><value>true</value></property>
    <property name="synchronizeOnSession"><value>true</value></property>
    This works fine, only for the first refresh. When the I tried for refreshing further (the second time onwards), the DB insertion is happening.

    Even I tried redirecting the user to the same form when duplicate submission is identified. This works fine with IE and not with mozilla.

    Code:
    protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response)throws Exception
    {
    ModelAndView duplicateModelAndView = new ModelAndView(new RedirectView(getFormView()));
    return duplicateModelAndView;
    }
    Please let me know, how to solve this issue?

    Thanks in Advance.
Working...
X