• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple Forms in Servlet/JSP

 
Ranch Hand
Posts: 45
Android Netbeans IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am using multiple forms in a JSP page (toggling with javascript).
I want to know if there is any way to have all three forms use one servlet. i.e. how can i identify which form is sending data from within the doPost() of the servlet apart from checking each getParameter() for null values (a long and tedious option!)
Thanks,
Stevie
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easiest: include a hidden input in each form that identifies the source. Ick.

Better: use a unique mapping for each variant. Meh.

Best: re-evaluate why you want to do this in the first place. If there are different actions that need to take place depending upon which form is submitted, why mash it all together? Sounds like a bad move to me.
 
Stevie Shorey
Ranch Hand
Posts: 45
Android Netbeans IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Easiest: include a hidden input in each form that identifies the source. Ick.

Better: use a unique mapping for each variant. Meh.

Best: re-evaluate why you want to do this in the first place. If there are different actions that need to take place depending upon which form is submitted, why mash it all together? Sounds like a bad move to me.



Thanks for the reply Bear. This is for a page which enables the user to add/modify/delete DB entries, so i thought it would be user friendly to have it all display on one page. Only one of these displays at a given time, so its not as messy to the user
Using a hidden field like you said, would this work?


Thanks,
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether the forms are on the same page or not is completely immaterial as to how they are processed on the server.

Why are you trying to jam this all into a single servlet?

 
Stevie Shorey
Ranch Hand
Posts: 45
Android Netbeans IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Whether the forms are on the same page or not is completely immaterial as to how they are processed on the server.

Why are you trying to jam this all into a single servlet?



That is very true. Yeah my reasoning (reducing amount of code/servlet files) was very faulty in trying to put everything in one place. Thanks!
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stevie Shorey wrote:That is very true. Yeah my reasoning (reducing amount of code/servlet files) was very faulty in trying to put everything in one place. Thanks!


Just to add on, you cannot improves on lines of code by giving up cohesion and increasing the coupling among components. Think of the maintenance nightmares that would follow .
 
reply
    Bookmark Topic Watch Topic
  • New Topic