Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on chaining servlets  RSS feed

 
Mike Dafel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building an application where I need to delete some users. I am getting the username from a form and then checking if it exists in the userlist. If yes, then I need a confirmation from the user to delete that user. Once confirmed, the user will be deleted.
So, I propose to use two servlets. One that will get the parameters from the form and then display the dynamic confirmation page having a submit button as a confirmation. This button would then fire a next servlet which would delete the user and then display that user has been deleted.
Kindly suggest how can I pass the values from one servlet to another. Some tutorial and sample code would be of great help.
And ofcourse, thanks in advance.
 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can forward from one servlet to another. And if you put the form values in a variables use the setArribute and getAttribute methods to transfer the variables from one servlet to another. So in the first servlet, you might have something like this:
request.setAttribute("nameYourParameter", "ValueYouWantPassed");
RequestDispatcher d = request.getRequestDispatcher("servlet2");
d.forward(request, response);
In servlet 2, you get the parameters this way:
String var1 = (String)request.getAttribute("nameYourParameter");
[This message has been edited by Jeff Sunder (edited July 23, 2001).]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Mike D",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!