Calling a servlet from another servlet?

HiI would like to know that how can I call one Servlet from another Servlet. I have tried getServlet() method of ServletContext but it has been deprecated. I want to call a specific method of the other Servlet, is there any other way?Thanks
[261 byte] By [beansday] at [2007-9-30 21:33:53]
# 1

I'd like to add here that i am also trying the following code:

RequestDispatcher rDispatch = null ;

rDispatch = getServletConfig ().getServletContext().getRequestDispatcher ("/Servlet2") ;

rDispatch.forward(request, response) ;

System.out.println("Back in 1");

but even then Servlet2 is not invoked. The doGet method of Servlet2 prints a certain line. When i execute Servlet1 the only output i see is:

"Back in 1"

What should i do?

beansday at 2007-7-7 3:05:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Since you are not gettng a 404 Page Not found error, there's nothing wrong with your forwarding.Post your Servlet2 code and may be we can help
jSweep at 2007-7-7 3:05:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

This is code from both Servlets.

Code of Servlet 1:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException

{

RequestDispatcher rDispatch = null ;

rDispatch = getServletConfig ().getServletContext().getRequestDispatcher ("/Servlet2") ;

rDispatch.forward(request, response) ;

System.out.println("Back in 1");

}

Code of Servlet 2:

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

System.out.println("In Servlet2");

}

beansday at 2007-7-7 3:05:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I should have seen it from your previous post :(

> Code of Servlet 1:

>

> public void doGet(HttpServletRequest request,

> HttpServletResponse response) throws

> ServletException, IOException

> {

> RequestDispatcher rDispatch = null ;

> rDispatch = getServletConfig

> ().getServletContext().getRequestDispatcher

> ("/Servlet2") ;

> rDispatch.forward(request, response) ;

> System.out.println("Back in 1");

> }

>

I assume Servlets 1and 2 are in same web app and you've mapped your servlet2 to /Servlet2 in your web.xml

make it as

rDispatch = request.getRequestDispatcher("/Servlet2");

rDispatch.forward(request,response);

....

Nothin's wrong with yer servlet2

jSweep at 2007-7-7 3:05:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
i have figured out the problem :), it was the name of servlet in web.xml which was servlet2 not Servlet2. I changed in Servlet1 and it worked. Thanks
beansday at 2007-7-7 3:05:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...