I'm typing this down now, so I haven't checked how well it will work,
but I hope you will get the general idea (sorry in advance for syntax
errors).

public void doGet(...) throws ... {

        // assuming web app is installed in /
        String root = getServletContext().getRealPath("/");

        String file = request.getParameter("myParam");

        ServletOutputStream out = response.getOutputStream();
        BufferedInputStream in = new BufferedInputStream(
        new FileInputStream(
                root + "/WEB-INF/myFunction/" + file + ".html"
            ),
            1024
      );

        response.setContentType("text/html");

        int i;
        while ((i = in.read()) != -1) {
                out.write(i);
        }

        out.flush();
        out.close();
        in.close();

}

[ Matthias Carlsson ]
[ Programmer (Java, XML/XSL, CGI/Perl, HTML/JS) ] [ Web Designer ]
[ E-Mail : [EMAIL PROTECTED] ] [ ICQ: 1430647 ]

> -----Ursprungligt meddelande-----
> Från: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]För Martin Cooper
> Skickat: den 15 mars 2001 08:25
> Till: [EMAIL PROTECTED]
> Ämne: Forwarding to a "private" path
>
>
> I just *know* this has to be an easy question, but my brain won't
> cooperate
> right now and give me the answer. It won't even come up with the
> right query
> for the archives. Apologies in advance...
>
> Given a particular request with the appropriate parameters, my
> servlet needs
> to ship back the contents of a static HTML file that lives underneath my
> WEB-INF directory. In other words, given a request such as:
>
> http://zaphod/myApp/myFunction?myParam=myValue
>
> I might want to return the file:
>
> ..... \WEB-INF\myFunction\myValue.html
>
> How do I do this?
>
> It seems to me that I need to use RequestDispatcher.forward(),
> but I haven't
> been able to figure out the right way to invoke it.
>
> Any help would be much appreciated.
>
> --
> Martin Cooper
>
> __________________________________________________________________
> _________
> 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

Reply via email to