This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes form being submitted twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "form being submitted twice" Watch "form being submitted twice" New topic
Author

form being submitted twice

vishal pala
Greenhorn

Joined: Jun 20, 2007
Posts: 4
Hi All,

We are having an problem our form being submitted twice and this happening very rarely around once in 2 months, per day this form is submitted around 2000 times. we are disabling the submit button after the button is clicked, Has any one of you have faced this problem if so please can you suggest the possible scenario when it happen As we are not able to recreate the problem in our development/Test environment

Logice is like we have a Jsp after the form is filled and when Submit button is clicked a servlet is called and in that servet we a have a method which perform the logice to create a string of message and sent to MQ queue. Problem is very rarely this same message is created twice and sent to Queue.

thanks in Advance for your suggestions.
vishal
Minh Tran
Greenhorn

Joined: Jun 03, 2007
Posts: 19
Just make sure the url has been redirected (changed), because user can still press refresh button to resubmit form


SCJP 1.4, SCWCD 1.4<br />email:mobject@gmail.com
vishal pala
Greenhorn

Joined: Jun 20, 2007
Posts: 4
hi Minh,

thanks for your reply, i have checked the URL its not changed and there is difference of fraction of milliseconds in the submitted messages, if we referesh the current page it takes some second again to submit, so i dont think it is happening with referesh and submit. thnanks!!
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Is it happening cross browser? Are you using a submit button image to submit the form. On IE if you use an image to submit a form (without any extra checks to stop the double submission) it would submit he form again. In case of Firefox it would only do a single submit. Please tell us thr browser and what exactly is the submit button?
vishal pala
Greenhorn

Joined: Jun 20, 2007
Posts: 4
Hi Anupam
thanks for your reply

we are using only Internet explorer 6.0 and we are not having any image on the button our submit is of type Button with onclick

i was trying to submit from other browsers in Test environment but unacle to create that scenairo, its happening in production environment all our user use only IE 6.0



thanks!!
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
I am sure you would be using a tracelog. You can insert debug statements in the beginning of service method and track from there
vishal pala
Greenhorn

Joined: Jun 20, 2007
Posts: 4
Hi rajesh
thanks for your response
Yes i have looked into my logs of production and what i see is there is just differnce of fraction of milliseconds on them timestamp of the messages, so two requests are sent to the servlet with in difference of fraction of milliseconds but not sure how it is happening in Prod envireonment that too very rarely thanks
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Hi Vishal,

Just check out these links.

  • Solving the Logout Problem Elegantly
  • Revisiting the Logout Problem



  • HtH.
    [ June 22, 2007: Message edited by: Raghavan Muthu ]

    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    Saravanan Thoppae
    Greenhorn

    Joined: Jun 30, 2007
    Posts: 13
    Hi Vishal,
    Since you said that the form will be submitted onclick event - i guess you would have submitted the form in a javascript. And please note that the form will be submitted when the focus is on the button and when the user hits enter key.
    So if you have called same javascript for onsubmit of form and onclick of the button then when the user hits enter (when button is on focus) the javascript will be called. But again there is a form submit called in a javascript and hence the double submit.

    Hope this helps.
    Venky Babu
    Greenhorn

    Joined: Mar 25, 2013
    Posts: 1
    Hi,

    Make sure that you have both doGet() and doPost() methods in your Servlet. If you have only one method, there are chances that can cause form submission twice.

    Please try this.

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    service(request, response);
    // TODO Auto-generated method stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    service(request, response);
    // TODO Auto-generated method stub
    }

    Thanks,
    Venky
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60741
        
      65

    Venky Babu wrote:Make sure that you have both doGet() and doPost() methods in your Servlet. If you have only one method, there are chances that can cause form submission twice.


    No, this is not correct. There is no way that only having one of these methods implemented can cause a double submission. No way at all.

    In fact, it is quite common to have only one of the methods implemented, and it is a poor practice to have both GET and POST do that same thing.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    wood burning stoves
     
    subject: form being submitted twice
     
    Similar Threads
    Servlet filter being invoked twice per request by Container.
    Disable form submit on carriage return in a text box for MAC systems
    disabling submit button not working
    submitting the invoice twice when submitt button is clicked
    jQuery UI Widget issue