• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Passing values from forms..

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...`
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...
Posts: 67269
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!