This is because once u have written something to the o/p stream in the
Servlet2, for displaying on the browser, then u cannot use forward anymore,
coz, the forward is for passing the control to the next servlet, which then
is supposed to write the o/p to the browser.U cannot write the o/p to the
browser from two servlets at a time.

that will solve your problem.

revert if u have any doubt.

Regards
----- Original Message -----
From: "Sushil Singh" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 14, 2000 3:21 AM
Subject: Re: RequestDispatcher


> Hi,
>
> I am again posting this question in shorter, please help me.
>
> I am having one servlet "Servlet 1" which displays a form, on form submit,
it
> calls another servlet "Servlet 2" which will do some process and then
redirects
> to servlet 1 using RequestDispatcher.
> 1.   Before redirecting to servlet 1, servlet 2 should produce html which
will
> display a popup window.
> 2.   Its perfoming perfectly i.e. it redirects to servlet 1 and display a
popup
> window. The only thing I am unable to understand is that still the url on
> browser is Servlet 2, which I think should be Servlet 1.
> 3.   I can not use "response.sendRedirect()" since my requirement is to
> redirect and display a popup window , which will give impression that this
> popup winodow is displayed by Servlet 1.
> This type of scnerio is required when dealing with multiple websites. Here
you
> can assume that "Servlet 1" is on one website and "Servlet 2" on another
> website.
>
> Also if anyone can provide difference between forward and include.
>
> Thanks in advance.
>
> Sushil
>
>
> Sushil Singh wrote:
>
> > Hi,
> >
> > Can anyone help me in understanding the function of RequestDispatcher.
> >
> > =======================================================================
> > First Servlet:  RdTest1
> > =======================================================================
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > public class RdTest1 extends HttpServlet
> > {
> >     public void doGet(HttpServletRequest req, HttpServletResponse res)
> >             throws ServletException, IOException
> >     {
> >        // Creating printerwriter object
> >        PrintWriter out = res.getWriter();
> >
> >        // Set content type and other response header fields first
> >        res.setContentType("text/HTML");
> >
> >        // Building page
> >        out.println("<HTML>");
> >        out.println("<BODY>");
> >
> >        out.println("<FORM name=\"rdForm\" action=\"/servlet/RdTest2\"
> > method=\"post\">");
> >        out.println("<CENTER><H3>URL Redirection - Request
> > Dispatcher</H3></CENTER>");
> >
> >        out.println("<BR><BR><BR><BR><BR>");
> >        out.println("Content from RdTest1");
> >        out.println("<BR><BR><BR><BR><BR>");
> >
> >        out.println("<INPUT TYPE=\"SUBMIT\">");
> >
> >        out.println("</FORM>");
> >        out.println("</BODY>");
> >        out.println("</HTML>");
> >    }
> >
> >    public void doPost(HttpServletRequest req, HttpServletResponse res)
> >             throws ServletException, IOException
> >    {
> >        doGet(req, res);
> >    }
> > }
> >
> > =======================================================================
> > Secound Servlet:  RdTest2
> > =======================================================================
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > public class RdTest2 extends HttpServlet
> > {
> >     public void doGet(HttpServletRequest req, HttpServletResponse res)
> >             throws ServletException, IOException
> >     {
> >      doPost(req, res);
> >     }
> >
> >     public void doPost(HttpServletRequest req, HttpServletResponse res)
> >             throws ServletException, IOException
> >     {
> >        // Creating printerwriter object
> >        PrintWriter out = res.getWriter();
> >
> >        // Set content type and other response header fields first
> >        res.setContentType("text/HTML");
> >
> >        out.println("Content from RdTest2");
> >
> >        file://res.sendRedirect("/servlet/UrlRed1");
> >        RequestDispatcher rd = null;
> >        rd =
> > getServletContext().getRequestDispatcher("/servlet/RdTest1");
> >        rd.forward(req, res);
> >
> >     }
> > }
> >
> > ======================================================================
> > The flow is: First servlet (RdTest1) is called from browser, on pressing
> > submit button, it will call secound servlet (RdTest2) which will forward
> > that request again to first servlet (RdTest1) using RequestDispather
> > service.
> >
> > The output which I am seeing is merged output of RdTest2 and RdTest1. On
> > browser, the url indicates the second servlet:
> > http://localhost/servlet/RdTest2
> > Here which servlet is having control, RdTest1 or RdTest2? Also if
> > anybody can help me understanding the difference between forward and
> > include, it will be highly appreciated.
> >
> > ==========
> > OUTPUT
> > ==========
> > Content from RdTest2
> > <HTML>
> > <BODY>
> > <FORM name="rdForm" action="/servlet/RdTest2" method="post">
> > <CENTER><H3>URL Redirection - Request Dispatcher</H3></CENTER>
> > <BR><BR><BR><BR><BR>
> > Content from RdTest1
> > <BR><BR><BR><BR><BR>
> > <INPUT TYPE="SUBMIT">
> > </FORM>
> > </BODY>
> > </HTML>
> >
> > ======================================================================
> >
> > Thanks in advance.
> >
> > Sushil
> >
> >
___________________________________________________________________________
> > 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: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to