Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Post executed twice when user clicks button to submit details

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 67430
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zane, are you perhaps executing a Javascript form.submit() within an onsubmit handler? That is one situation where I've seen this happen.
P.S. Welcome to the Ranch!
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
[ yoiks, smilie error ]
[ July 02, 2003: Message edited by: David O'Meara ]
Zane Tofie
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic