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?
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");
}
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