Richard Yumul wrote:

> Thanks for your help!  I did see the API documentation on how the client side
> variables are accessed through the method calls, I guess I should have been more
> specific; would you know how to access those server variables, set by apache?
>

The only environment variables you can see directly are those that are
automatically translated into methods of HttpServletRequst.  For example, if you
wanted to print out the value of the SCRIPT_NAME environment variable (which is
made available, as the API docs indicate, in the getServletPath() method), you
would do something like this:

    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
    {

        PrintWriter writer = res.getWriter();
        writer.println("<html>");
        writer.println("<head>My Servlet Response</head>");
        writer.println("<body>");
        writer.println("My servlet was called at SCRIPT_NAME = " +
            req.getServletPath() + "!");
        writer.flush();

    }

Check in the API documentation for which method call corresponds to which
environment variable.

For more examples, download the Java Servlet Development Kit (JSDK) at
http://java.sun.com and peruse the sample servlets -- especially the SnoopServlet,
which dumps out essentially everything the servlet can possibly know about its
environment.  Note that these calls work in *every* servlet engine, not just Apache
JServ.

As stated earlier, DOCUMENT_ROOT is *not* a standard CGI environment variable.
However, you can find out what it was passed as  (in Apache JServ *only*) by doing
this:

    String documentRoot = req.getRealPath("/");

NOTE:  Apache JServ does not know anything about aliasing you might be doing in
your Apache installation.  If you really want to retrieve documents based upon
their URL, you should use a java.net.URLConnection.  See the Java Language Tutorial
(again at java.sun.com) for more information.

Craig McClanahan




----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to