• Post Reply Bookmark Topic Watch Topic
  • New Topic

reusing my servlet

 
Tontang Bei
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. ?
 
Hussam Bamatraf
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.
 
Ryan Day
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!