jang eui jin wrote:

> In my FileServeServlet, the HTML file is served as follow;
> ---------------------------------------------------------------------------------
>
> public void service(HttpServletRequest ...
> //...
> String path = req.getPathTranslated();
> try {
>    fis = new FileInputStream(path);
>    byte[] buf = new byte[1024 * 4]; // 4K buffer
>    int bytesRead;
>
>    while ( (bytesRead=fis.read(buf)) != -1 ) {
>     out.write(buf, 0 , bytesRead);
>    }
> //....
>  ---------------------------------------------------------------------------------
>
> It works fine. But, I have no idea about serving jsp files.
>
> How can I serve jsp files in FileServeServlet?
>

The RequestDispatcher class was added in the 2.1 API for this purpose.  If you want
to simply forward control to a JSP page that will create all the output, do something
like this:

    RequestDispatcher rd =
        getServletContext().getRequestDispatcher("/my/page.jsp");
    rd.forward(request, response);

To include the output of a JSP page in the output you are creating (a program-driven
server side incluce), do this instead:

    RequestDispatcher rd =
        getServletContext().getRequestDispatcher("/my/page.jsp");
    rd.include(request, response);

However, by far the easiest way to deal with JSP pages is to set your servlet engine
up so that URIs that end with a ".jsp" extension are automatically handled by
your JSP engine's servlet.  The way to do this depends on which servlet engine you
are running, but most (probably all) provide this extension mapping capability.

Craig McClanahan

___________________________________________________________________________
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