• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet chaining

 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HAI

CAN ANYONE LET ME KNOW HOW TO CALL A SERVLET FROM OTHER SERVLET

POOJA
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only if you stop shouting at us. Turn off caps lock please. Tell us what you want to accomplish (Why you want to call a servlet from another servlet), what container you are using, and are both servlets running in the same container?

Kyle
 
Pooja Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Kyle,

Sorry for using caps lock.
This is an interview question which has been asked.

Pooja A.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are different ways to do that

1 - you can use response.sendRedirect("/secondServlet") to redirect to another servlet.

2 - You can forward request to another servlet using

RequestDispatcher rd = request.getRequestDispatcher("/secondServlet");
rd.forward(request,response);

3 - You can also call another servlet by using form tag of HTML
out.print("<form method=post action='/secondServlet'>");

4 - You can also make a link using <a tag of HTML

out.print("<a href='/secondServlet'>Click Here</a>");

But Rule 3 and 4 are not used because it is not convienient to do that. Servlet should not contain the presentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!