On 10/28/05, Laurie Harper <[EMAIL PROTECTED]> wrote:
>
> Craig McClanahan wrote:
> > On 10/27/05, Laurie Harper <[EMAIL PROTECTED]> wrote:
> >
> >>I feel like I should know the answer to this one but I seem to be
> >>stumped... How do I get the actual request URI (or URL) in a JSP that's
> >>included via Tiles?
> >>
> >>Both ${pageContext.request.requestURI} and
> >>${pageContext.request.requestURL} are pointing to the Tiles layout JSP,
> >>whether or not I include an <html:base/> tag in the <head> section in
> >>the layout.
> >>
> >>To be exact, what I actually need is the full context-relative request
> >>path -- and I'm using URL prefix mapping, so for example the URL I
> >>browse to would be http://host/bin/some/path and the bit I need is
> >>'/some/path'.
> >
> > If you're within the context of a RequestDispatcher.include() -- which
> is
> > what Tiles is doing under the covers -- the servlet container promises
> to
> > create some request attributes for you that contain useful information
> about
> > the included URI, rather than the original request URI. In particular,
> the
> > attribute named "javax.servlet.include.request_uri" will include what
> you
> > are looking for. Other attributes of interest:
> > * javax.servlet.include.context_path
> > * javax.servlet.include.servlet_path
> > * javax.servlet.include.path_info
> > * javax.servlet.include.query_string
> >
> > (See section SRV.8.3.1 of the Servlet Spec for more info.)
>
> Thanks for the reference; I'd seen those attributes but wasn't sure if
> they were standard or not. Unfortunately, I don't think they solve this
> particular problem; request_uri has the context-relative path of the JSP
> page included by Tiles, but that doesn't match the original request URL.


Ah ... there might be a timing issue here, depending on when you ask the
question.

If you ask this question inside an Action.execute() method, the original URI
is available via request.getRequestURI() ... doing a
RequestDispatcher.include() call does not change those path properties.

However, Struts does a RequestDispatcher.forward() at the end of the request
processing lifecycle (i.e. after your Action.execute() method returns). At
that point, the container modifies the path properties in the request to
reflect the page (or tile) that you forwarded to.

Now, if you're on a Servlet 2.4 container (Tomcat 5.x, for example), all is
still not lost. There is a corresponding set of request attributes (
javax.servlet.forward.request_uri and friends) that will be set to reflect
the original request, so you can ask this question (for example) from within
a tile's JSP page.

On a pre-2.4 container, this feature won't be available ... but it is
something you could probably program into a custom RequestDispatcher
implementation.

I think what's going on there is that Tiles is doing multiple, nested
> includes so I'm still at least one too many steps removed from the
> original request.
>
> L.


Craig


---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to