How to communicate between two servlets?

ANS: Two ways:

1. Forward or redirect from one Servlet to another.

2. Load the Servlet from ServletContext and access methods.

Showing Answers 1 - 3 of 3 Answers

Anand

  • Aug 29th, 2005
 

Using RequestDispatcher interface

  Was this answer useful?  Yes

Chidambara Gupta. Cheedella

  • Sep 21st, 2005
 

Servlet Collaboration or Communication can be achieved either by using Request Dispatcher's Forward or Include methods (available with request object) or Send Redirect method(available with response object). Servlet Context  is also one of the ways to acheive servlet collaboration coz it is the one which provides the information of all the servlets.

  Was this answer useful?  Yes

Rakesh Parashar

  • Jan 19th, 2006
 

Through RequestDispatcher by obtaining object of type RequestDispatcher by
getRequestDispatcher() method of ServletContext but before getting object of
ReqestDispatcher we have to first obtain object of type ServletContext by
getServletContext() method of ServletConfig
Once we have RequestDispatcher object we can forward reqest by its forward() method
or we can include that reqest in a perticular page by calling its include () method
code will be:

servletContext sc=this.getservletContext();

RequestDispatcher rd=sc.getRequestDispather();

rd.forward("URI of page where u want to forward reqest");

Please comment..............


 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions