Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing values from forms..  RSS feed

 
Pandurang Shenoy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm relatively new to JSP and HTML..i wud like to know how can i pass the values entered in two different forms on a single page to a servlet which is invoked...`
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to my understanding, you have 2 forms in a jsp page. But I want to know, do those forms refer to a servlet?
If those forms refer to a servlet, i think you can only have one form instead of two form.
If those forms do not refer to a servlet, you can just fill the name of servlet in action field ( attribute of FORM tag) for each form....
Correct me if i am wrong...
daniel
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, if you need to have the union of the controls in the two forms sent to a single action (in this case your servlet), I'd step back from the code for a second and re-evaluate why you have the controls in two separate forms in the first place.
If you come to the conclusion that you have a really good reason for having the two separate forms, there are a number of tactics you can use.
The simplest would be to have the first form contain hidden field controls that mirror the visible controls in the second form. Upon form submission, the values in the visible form fields (in the 2nd form) can be copied via JavaScript to the hidden fields in the first form and thus be submitted to the servlet along with the fields of the first form.
But again, I'd urge you to reflect on your design before putting this kind of mechanism in place to see if it is really necessary in the first place.
hth,
bear
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!