List Info

Thread: Re: Read file from docroot




Re: Read file from docroot
user name
2007-11-06 12:58:44
Passing a path that starts with "../" as an
argument to ServletContext.getResource() is invalid (and
will cause an error) as per the javadocs of
ServletContext.getResource(String path):

     * Returns a URL to the resource that is mapped to a
specified
     * path. The path must begin with a "/" and is
interpreted
     * as relative to the current context root.

This means that the use of this API will be portable across
containers.

As for being able to update the returned resource, the
javadocs also specifies this:

     * Some containers may allow writing to the URL returned
by
     * this method using the methods of the URL class.


Jan
[Message sent by forum member 'jluehe' (jluehe)]

http://forums.java.net/jive/thread.jspa?messageID=244128


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeglassfish.dev.java.net
For additional commands, e-mail: users-helpglassfish.dev.java.net


Re: Read file from docroot
user name
2007-11-06 13:47:03
Thanks for correcting, Jan.

But since docroot is not part of any context, it won't be
possible to use
this technique to read/write files from docroot.

So, I guess the only solution is to use
ClassLoader.getResourceAsStream() and then
passing the relative path. Is that right?

Thanks,
Kedar
[Message sent by forum member 'km' (km)]

http://forums.java.net/jive/thread.jspa?messageID=244138


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeglassfish.dev.java.net
For additional commands, e-mail: users-helpglassfish.dev.java.net


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )