Petr Jiricka wrote:

> Hi,
> I wonder if this is a bug or just "behavior":
> Calling
>
>   config.getServletContext().getRealPath("servlet/ServletName")
>
> returns null in JSWDK 1.0 EA if the document base for this context is set to
> a http URL (http://localhost:8082/repository/ in my case). The javadoc for
> this method says
>
> "This method returns null if the translation could not be performed for any
> reason.",
>
> but I can't see why this could not be translated to
> "http://localhost:8082/repository/servlet/ServletName".
>
> Any ideas ?
>

That's a simple one ... "http://........." is a valid URL, not a pathname in
the local file system.  A pathname would be something you could pass to the
file I/O routines and open.

If you want to do the translation that you've described, use getResource() to
get a URL instead of calling getRealPath() to get a pathname.  Then, you can
open a URLConnection to read the content of the resource, or let the servlet
engine do it for you by calling:

    InputStream is =
        getServletContext().getResourceAsStream("servlet/ServletName");

and then read from the input stream.  This will work whether the doc base is
set to a directory or an HTTP URL.

>
> Thanks
> Petr
>

Craig

___________________________________________________________________________
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