The request dispatcher is used to further process a request by a different
servlet.  I would use sendRedirect on the response object to redirect to an
HTML page.  This is not such a good idea though if you do it as a correct (read
default) behaviour because the redirect response comes back to client and then
gets the document specified in the sendRedirect's argument (extra round trip).

Also this isn't really chaining.  If you want to have a servlet that's fetching
pages for people then you should open an IO stream to a requested file and
reply with the stream of that file to client.

dave.

Dominique Chaniat wrote:

> I have a problem when I want use RequestDispatcher.
>
> I work under Windows, with JSWDK 1.0, and I compile my code with JDK 2.0
> and Servlet API 2.1.
>
> When I try to run my code, I get 404 error, but I execute the followed
> lines (requestDispatcher.forward(request, response);
> System.out.println("Chaining done");). because the requestDispatcher is
> not null. I have verified, the file index.html exists under the root
> directory of the http server (http://localhost:8080/index.html is good).
>
> Can you help me please.
>
> Thank in advance.
>
> import java.io.*;
> import java.util.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class ServletChain2 extends HttpServlet {
>
>   public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws IOException, ServletException {
>     System.out.println("Initializing servlet");
>
>  //   RequestDispatcher requestDispatcher;
>     RequestDispatcher requestDispatcher =
> getServletContext().getRequestDispatcher("/index.html");
>
>     if (requestDispatcher != null) {
>       requestDispatcher.forward(request, response);
>       System.out.println("Chaining done");
>       }
>       else {
>       response.sendError(response.SC_NO_CONTENT);
>       System.out.println("Chaining failed");
>       }
>
>   }
> }
>
> ___________________________________________________________________________
> 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

--
David Mossakowski              [EMAIL PROTECTED]
Programmer                           212.310.7275
Instinet Corporation

"I don't sit idly by, I'm planning a big surprise"

___________________________________________________________________________
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

Reply via email to