Hi Vasu,
If you want to forward the servlet2 to servlet3 you shouldn't obtain the
writer or the output stream in servlet2.
So delete the writer and the related lines in servlet2. try the following:
///////////////////////////////////////////////////////////////////////
public class HelloWorldExample2 extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse
response)
{
try
{
getServletConfig().getServletContext().getRequestDispatcher("HelloWorldExample3").forward(request,
response);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
///////////////////////////////
i guess servlet2 n servlet3 are in the same directory, if so u can refer to
servlet3 directly as above. else change the path as is reqd, relative to the
servlet2
Have servlet3 as it is..
It shld work!!!!!
Revathi
>From: Vasu Yalavarthi <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: Servlet-to-Servlet Communication
>Date: Fri, 8 Dec 2000 15:47:04 -0800
>
>Hi Thomas,
>It is still not working.
>
>The following is the source code for both the servlets.
>Let me know if i'm still missing something....
>
>/////////////HelloWorldExample2(Servlet1) Code/////////
>public class HelloWorldExample2 extends HttpServlet {
> public void service(HttpServletRequest request, HttpServletResponse
>response)
> {
> try
> {
> PrintWriter out = response.getWriter();
> response.setContentType("text/html");
>
>getServletConfig().getServletContext().getRequestDispatcher("/examples/servlet/HelloWorldExample3").forward(request,
>
> response);
> out.flush();
> }
> catch(Exception ex)
> {
> ex.printStackTrace();
> }
> }
>}
>
>///////////////////End HelloWorldExample2///////////////////
>
>//////////////////// HelloWorldExample3(Servlet2) Code ////////////////
>public class HelloWorldExample3 extends HttpServlet {
> public void service(HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException
> {
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
> out.println("Hello World Servlet Three");
> }
>}
>
>////////////End HelloWorldExample3 ////////////
>
>"Thomas, Omar" wrote:
>
> > Vasu,
> >
> > Well the ServletConfig object is an implicit object in the service
> > method so don't have to create it... what you can try to do is ...
>instead
> > of instantiating ServletConfig and ServletContext.. try
> >
> > //////////////Code Servlet 1 - service() method//////////
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> >
>getServletConfig().getServletContext().getRequestDispatcher("/examples/servl
> > et/HelloWorldExample3").forward(req, resp);
> > out.flush();
> > //////////////End Code///////////////
> >
> > this will work ..
> >
> > -----Original Message-----
> > From: Vasu Y [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, December 08, 2000 2:20 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: Servlet-to-Servlet Communication
> >
> > Revathi,
> > I tried RequestDispatcher.forward(request, response), but doesn't work.
> > The following is the code I tried on Tomcat 4.
> > Both the servlets are deployed on the same machine.
> >
> > Can u tell me if I'm missing something....
> >
> > //////////////Code Servlet 1 - service() method//////////
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> > ServletConfig config = getServletConfig();
> > ServletContext context = config.getServletContext();
> > RequestDispatcher dispatcher =
> > context.getRequestDispatcher("//examples//servlet//HelloWorldExample3");
> > dispatcher.forward(request, response);
> > out.flush();
> > //////////////End Code///////////////
> >
> > //////////////Code Servlet2 - service() method//////////////
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> > out.println("Hello World Servlet Three");
> > //////////////End Code///////////////
> >
> > Thanks,
> > Vasu
> >
> >
>___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
>body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> >
>___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
>body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html