• Post Reply Bookmark Topic Watch Topic
  • New Topic

a doubt in servlet invocation..  RSS feed

 
Vidya Sreenivasan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
I am relatively new to servlets, and this is my first post here.
Is there any way i could know which form triggered the servlet, like if I submitted one form, i need the servlet to do one task, and if I submitted another form, i need the same servlet to do another task.
I am thinking of checking for a condition in the servlet's doGet() method, and accordingly , call approppriate methods.
Is it possible i could check which form triggered it, inside its doGet() method ? like, if the request is from form1, do this, and if the reguest is from form2, do something else ..
any help would be appreciated.
thanks..
Vidya.
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Vidya!
In form maintain one hidden field and give some name say "form1". After submit in servlet get that parameter then do what ever u want to do for form1
Like this.....
In form
<HTML>
<BODY>
<FORM>
.......
.......
<Input type="hidden" name="FormName" value="Form1">
.......
.....
</FORM>
</body>
</HTML>
In servelt
public void doGet(request,response)
{
///////////
String strFormName=(String)request.getParameter("FormName");
....
.......
if(strFormName.equals("Form1"))
{
////Action for Form1 goes here..........
}
else if(strFormName.equals("Form2"))
{
////Action for Form1 goes here..........
}
///And so on......
..........
}
Hope this might help u..
Rgds
Manohar
 
Vidya Sreenivasan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks a lot Manohar..
good idea..
regards,
vidya.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!