This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes submitting two forms with one button click from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "submitting two forms with one button click from JSP" Watch "submitting two forms with one button click from JSP" New topic
Author

submitting two forms with one button click from JSP

DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
Hi,

I have a requirement to submit two forms ( each form to a different strut action class ) on click of a submit button from JSP. Any idea how this can be achieved? Is it OK if i write a java script method and inside the method i write the two form submit as below?



Please let me know if there is any other way of doing it.By the way form1 will submit to a different url (different application) and form2 will submit to an action class on the same application.
Also i have read that two forms can't be submitted from a JSP at the same time.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

You cannot submit two requests at the same time. Which one's response would show up in the browser?

Back up. Why do you need to do this. There is surely a better way.

(P.S. You could possibly use Ajax, but I'm not sure that's the best approach.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

That's impossible! Why don't you combine two forms into one, and two actions into one?


PM Me If You Want to get Urgent Help on Java Programming
DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
ok. Let me explain my requirement in detail.

I have an OK button on my JSP and on click of that OK button, i am suppose to send some parameter as POST to another application in a new window( i.e. a new browser window should open on click of OK). At the same time, i also need to forward the request to another screen which is a summary screen on the same application. So it is not possible for me to combine these two activities into one.

Also how Ajax can help here?

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

DeepakN kumar wrote:


If you submit 2 forms, the last one will get submit . so this is not correct approach. and I think, I got your requirement. just follow the below steps,

create 2 forms like below, first one will be your main window and second form will be submitted to your popup(see the target attribute)


and onclick javascript



does that make sense?

DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
thanks i will try this. But i have one question. Here also there is two form submit right? So in this case also only the last submit will work right? (document.getElementByID('go').click) ? Please could you explain?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

but there are 2 windows . form per window. i.e, submit per window.
DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
thanks alot. Also is there a difference between submitting the form by document.getElementById("go").click() and document.getElementById("hidden").submit()? both are same?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

DeepakN kumar wrote: both are same?

it is same here :)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: submitting two forms with one button click from JSP
 
Similar Threads
Find requested source form
two actionForms for one action class?
How to submit two forms on same page?
Tiles Multiform submit
how to call different java script codes on different button click