aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Form submission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Form submission" Watch "Form submission" New topic
Author

Form submission

ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 214
is it possible to submit two forms in one jsp ,

Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
Yes it is possible but not on a single event.


Regards,
Mahesh Kedari - Fidus Technologies Ltd.
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 214
will you please explain it
John Pradeep.v
Ranch Hand

Joined: Jul 21, 2008
Posts: 59
may be you can write an onclick event handler on one form submission and trigger the second form (obtained by the id) submission through the script... not very sure of how it might work as I never tried it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, this isn't really possible: a page can only submit a single form at a time. What would it mean to submit two forms? If they're submitting to the same action there's no need for two of them, and submitting to two places makes no sense.

You *can*, however, use an onsubmit/etc. to add form values or fill in hidden forms so the values from both forms are submitted to the *same* action.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

What are you really trying to accomplish? Focus on strategy rather than tactics.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 214
Yes i need to perform diffent action , i need to call two jsps for two differnt forms

can i call on submit on first form in that function i will submit both the forms

..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

You're still not telling us anything. You're focusing on tactics... what do you really need to do?
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 214
Ok OK ... boss
My problem is i have input dialog when i click on submit button of input dialog i need to invoke another output page ,
after opening output page i need to refresh input page
i am doing this in process jsp,
the probelm is i need to send long url to putput page which is not working in IE by passing it as url parameter so i need do POST thats why i need two form submission in process JSP
so i can pass my parameters tru hidden fields ,,

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

No, you don't need two submissions. If you a trying to work around a URL length issues, just use a POST rather than a GET and provide the params as hidden inputs to a post form.

You could also consider employing Ajax to make the request.
John Pradeep.v
Ranch Hand

Joined: Jul 21, 2008
Posts: 59
Bear Bibeault wrote:No, you don't need two submissions. If you a trying to work around a URL length issues, just use a POST rather than a GET and provide the params as hidden inputs to a post form.

You could also consider employing Ajax to make the request.


Hi Bear, You are right in the solution... but just trying to look at his problem as a puzzle to solve, i think it should be possible to achieve the same affect of two form submission using 2 AJAX requests right? i mean two synchronous AJAX post requests without refreshing the page.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

Yes, if you want multiple requests, Ajax is a way to do that. I still question the need for multiple requests though...
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hello,

I agree when anyone says that a HTML FORM cannot be submit twice. All's well and fine. Listen to something that happened to me a while back.

This involves a team mate and during a review I found that the person was using a <input type="button" onclick="javascript:..."> instead of a <input type="submit onclick="javascript:..."> for FORM submission. The idea was that the client side validations would be performed inside the script function and then a call would be made to document.forms[.].submit(); (in case of multiple forms on the same page, as is very common these days). I guess the necessary changes were made and later issues arose when a person tried to register him/her-self as an user (just another scenario). What was happening was given the credentials ANY user would always get the error message that the same user/user-id was already registered .... On checking the database we found that the user was inserted there and after multiple test sequences we deduced that such a thing is not really impossible?

Or maybe its a browser deal? But even though we tried on IE (forgot the version) and Firefox (the same applies) results were similar.

This whole deal is way beyond my comprehension (two form submissions from the same form, without AJAX). BUt hey does anyone wanna try this one out?

Raj.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

I'm willing to bet you submitted the form twice. Check the validation script to see if there's a call to the form's submit() function. If so, the form is being submitted once by script, and once by the default action of the submit button.

Either don;t do it in script and let the button do its thing, don't use a submit button, or cancel the default action of the submit button by returning false from the event handler.
John Pradeep.v
Ranch Hand

Joined: Jul 21, 2008
Posts: 59
Raj Kamal wrote:

Or maybe its a browser deal? But even though we tried on IE (forgot the version) and Firefox (the same applies) results were similar.



Logically when a form is submitted, the browser opens a socket to the server to port 80 and sends an HTTP message, if another form submission happens then it will open another new socket and submit the content with an HTTP post message so in theory multiple form submission is possible if the browser interprets every user event independently in a new "thread" to handle socket creation and response interpretation, but it is not clear how will the browser handle 2 responses!!? will it consider the last response obtained as the response to process?

But in Practical, I think browsers have some restrictions in making multiple requests at the same time, we my have to dig into the implementation details to understand it in a better way.
I can assume that every interaction of the browser with any external Server should be sequential i.e., when a form is submitted the life of that page is expired and the browser just waits for the response for the first form submission and ignores listening to any new event on the already submitted page.

however, the exception is the usage of asynchronous AJAX in which case i believe the browsers would create a new thread to collect the AJAX response when it arrives and the page is always "alive" from the browsers perspective! Again, it all depends on the implementation details which could be actually different than what i said but may be a similar concept.


Thanks,
John
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 214
Ok ... if i dont want to use any form submission i want pass my long long url using window.open() without any data lost ...

Is it possible with window.open to pass long url
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There is a limit to how long a URL can be, and it's browser-dependent.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form submission
 
Similar Threads
how to add values to servlet and call that servlet
WA #2 ..... word association
Value from select element is null in request
validation.xml NullPointerException
Words that differ by one letter