• 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 ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

reusing my servlet  RSS feed

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp(newCustAc.jsp) that accepts some user's details and forewards them to a servlet which basically does some formatting to some part of the input and then calls the add() of a helper class to have it inserted into the Dbase.

Now, I have another jsp(renewCustAc.jsp) that does the same thing of accepting user's input. I want to reuse the same servlet as above that does the formatting and the inserting but instead of calling the add() of the helper class I want to call the update() of that class. How can I do this?. Is there some way to interrogate from which URL the request is coming from and then do some kind of If test to call the appropriate method. ?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily add a parameter in the forwarded request to specify which action to execute, for example, use the following URL to forward to your servlet if you want to execute the add() method:
/MyServlet?action=add

Then inside the servlet's doGet() method retrieve the value of the action parameter to decide which method to call:


I hope this will help you.
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the idea, I will try it.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a good candidate for a hidden field in the form. Won't show to the user but will be sent as a request parm to the Servlet.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!