users@glassfish.java.net

Re: Help with docroot

From: <Jan.Luehe_at_Sun.COM>
Date: Tue, 18 Sep 2007 16:08:25 -0700

glassfish_at_javadesktop.org wrote:

>Search around for references to alternatedoctroot. It's in GFv2, and it works really well.
>
>In essence, you put an entry in your sun-web.xml (among other places).
>
> <property name="alternatedocroot_1" value="from=/images/* dir=/usr/gifs"/>
>
>So, this would map:
>
>http://yourhost.com/images/pic.gif
>
>to
>
>/usr/gifs/images/pic.gif
>
>The key is that you while you specify a path to mount the doc root on (in this case /images), the value you give it is actually the root of the request, so you need to create a /images directory underneath it.
>
>So, as I said, pic.gif maps to:
>
>/usr/gifs/images/pic.gif
>
>vs
>
>/usr/gifs/pic.gif
>
>The point is subtle and it's easy to get confused when your content doesn't work.
>
>

Thanks for this reply, whartung!

To elaborate on the "subtle point" you mention:

When attempting to match a request to one of the context's alternate
docroots (if any), the "context path" component of the request URI is
ignored (this is consistent with how a request is matched to one of the
context's declared servlets, based on their URL patterns).

In case a match was found, the alternate resource path is computed by
appending the request's path info (i.e., the result of calling
HttpServletRequest.getPathInfo()) to the alternate docroot that was
matched.

Using your example, if you deployed your webapp at "/myroot" and accessed
this URL:

  http://yourhost.com/myroot/images/pic.gif

the request's path info would be equal to

  /images/pic.gif

resulting in an alternate resource path of

  /usr/gifs/images/pic.gif

Likewise, if you deployed your webapp at "/" (the root context) and accessed
this URL:

  http://yourhost.com/images/pic.gif

the request's path info would also be equal to

  /images/pic.gif

resulting in the same alternate resource path of

  /usr/gifs/images/pic.gif

Hope this helps.


Jan