struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: [S2] current URL in ValueStack?
Date Mon, 21 Jul 2008 02:12:09 GMT
Pierre Thibaudeau wrote:
> Earlier in this conversation, Jeromy proposed two ways of accessing
> the current URL (or URI), one through EL and the other through OGNL
>
>   
>> ${pageContext.request.requestURI}
>> <s:property value="%{#context['com.opensymphony.xwork2.dispatcher.HttpServletRequest'].requestURI}"/>
>>     
>
> That works great until (it seems) Tiles2 gets in the picture.  By that
> point, the address returned is that of the Tiles layout (with
> extension ".jsp") and not the logical address of the request.  (I
> haven't made a systematic study of the exact conditions for this
> phenomenon to occur.)
>
> It seems to me that, having access to the current (logical) URL (the
> one that generated this request) is a fairly common need.  Has anyone
> come up with another way of getting hold of it?
>   

I was hoping you wouldn't encounter that little problem.  When your 
container forwards to a JSP, the requestURI is now the JSP rather than 
the original URI.

After a forward, the requestURI is now available in the request map:

#request['javax.servlet.forward.request_uri']

But of course, that won't be set if there wasn't a forward, so you can't 
always use that.

As logic's involved, my solution was to create a custom tag with the 
following code extract.  I never understood why the requestURI was never 
readily available in the action's context though. However I rarely need 
it and most pages don't require it.

Snippet:
            StringBuilder uri = new StringBuilder();
            RequestMap requestMap = (RequestMap) 
stack.getContext().get("request");
            String forwardURI = (String) 
requestMap.get("javax.servlet.forward.request_uri");
            if ((forwardURI != null) && (forwardURI.length() > 0)) 
{          
                   uri.append(forwardURI);              
            } else {
                   uri.append(request.getRequestURI());              
            }


regards,
 Jeromy Evans


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message