my dog learned polymorphism*
The moose likes Servlets and the fly likes Post executed twice when user clicks button to submit details 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 "Post executed twice when user clicks button to submit details" Watch "Post executed twice when user clicks button to submit details" New topic
Author

Post executed twice when user clicks button to submit details

Zane Tofie
Greenhorn

Joined: Jul 02, 2003
Posts: 3
I have a vexing problem. When a user clicks a struts html:image button, it seems that the POST is executed twice - resulting in two database inserts when only one should have been made. I'm using WSAD 501 and a tomcat 406 server.
The flow of execution is as follows:
The user clicks a menu item to request the page.
This 'fires an init action' that places several arraylists in the session scope - and then the init action forwards to the actual jsp that the user will use to enter his details.
This JSP contains two sets of logic:equal tags.
When the user makes a certain selection he has to fill in more details which is shown as a second 'view' in a wizard-style fashion.
The logic:equal tag sets enclose two tables each with its own html:image button.
After the user has filled in his details and if the user is not required to do the extra step and the user clicks to submit the form, then the console shows that the POST was executed twice for the /registrationAction. For a single click, all the sys outs appear twice and two inserts are made into the db. The interesting things is that each of the two inserts have unique ids that a business bean provides.
I'm at a loss as to why this is happening - a single click executes the POST twice.
I would really appreciate any advice. I've googled and can't seem to find any solution. I've changed scopes and implemented the registration differently but still the same thing happens.
Please let me know if I need to provide code etc.
Many thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

Zane, are you perhaps executing a Javascript form.submit() within an onsubmit handler? That is one situation where I've seen this happen.
hth,
bear
P.S. Welcome to the Ranch!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yep, I've seen the same thing in IE when you have a submit button that executes functionality that also results in a submit... ie:

The combination of input type=submit and myForm.submit() causes the form to be submitted twice for a single click.
(oh, and UBB doesn't like on_click, hence the underscore)
Dave
[ yoiks, smilie error ]
[ July 02, 2003: Message edited by: David O'Meara ]
Zane Tofie
Greenhorn

Joined: Jul 02, 2003
Posts: 3
Great stuff, spot on - thank you guys! I removed the call to the java script and implemented image button beans as explained in a tip by Ted Husted - and it works just fine now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Post executed twice when user clicks button to submit details
 
Similar Threads
Servlet filter being invoked twice per request by Container.
disabling the html:image
How to call variables in one applet using another applet?
Struts and Mozilla
Multiple submits from a page...