• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prevent form double submit

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my form, based on various events like change in dropdown etc, the form is submitted each time. Each time the form is submitted, a value for option is set which is passed to servlet processing. So for each event, I have a separate function in which I set the value of option and then the form is submitted using document.form.submit.

Now, I have to find the event due to which the double submit for form happens. When the double submit happens, in the second submit the value of option as well as request attributes are set to null and so in servlet I get null pointer exception.

I see null pointer exception in production logs at random but its really hard to guess which user action causes the null pointer exception. My question is if anyone has script or any other technique to prevent form double submit. I know there are ways to handle user double click for submit button but in my case the events are change in dropdown etc.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe Struts has an answer for this. Or work around would be having a static variable and put condition on it.

Thanks.
Jetendra Ivaturi
 
sumeet sumeet
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jetendra,
Thanks for your reply. Unfortunately, I am not using struts framework. I just need a quick fix. Can you please elaborate on the other workaround of using static variable?
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean to say We can define variable in scriptlets,

<%! ... %>

. Increment that variable when ever an submit botton is pressed and put a validity condition on it.

Would that help?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jetendra Ivaturi wrote:I mean to say We can define variable in scriptlets,

<%! ... %>

. Increment that variable when ever an submit botton is pressed and put a validity condition on it.

Would that help?


Aside from the fact that scriptlets should no longer be used in JSPs, do you realize that this will be shared across all instances of the JSP? This will allow one user to press the button once, and then no one else will ever be able to press the button again.
 
sumeet sumeet
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had thought about implementing the counter which can be checked before submit.
However, the user can do multiple events on the page one by one and each event will cause the form to submit.
I don't want to prevent those submits.

What I want to prevent is double submit because of single event.
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear.

sumit

Are you using the submit to fetch some data into the page? What the exact senario you are looking for ?

If you are looking to update the page, using AJAX would be a good move I think.

 
sumeet sumeet
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, There is no submit button.

On the JSP page, the user can do various things like attach a word document, change the drop down which changes the attachment. All this information is eventually stored in a bean.
So for e.g, when the user changes the dropdown, the form has to be submitted and control passes to the servlet. Since each dropdown value has a different attachment and it has to get the attachment number etc from the database.

So after each event, the form has to be submitted. But somewhere there seems to be a double submit happening for a single event since in the second submit, the request parameters are null. Its a small bug fix for which implementing AJAX/Struts might be a costly solution for us.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sumit patki wrote: But somewhere there seems to be a double submit happening for a single event since in the second submit



I am not sure about your problem. it might not be double submit problem .

If you want to prevent double submit . put token into the session and make it hidden field of your form and then remove the token in your first submit
 
reply
    Bookmark Topic Watch Topic
  • New Topic