You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by doahh <ga...@prodia.co.uk> on 2008/10/17 14:12:18 UTC
Strus2, Freemarker and getting request.getContextPath()
I expect this is probably very easy but I have not seen and description
anywhere of how to do it. I currently have this in a Struts2 enabled jsp
page:
<%request.getContextPath()%>
and need to convert it to freemarker. I have tried the obvious:
${request.contextPath}
${request.getContextPath}
and also adding a servlet filter (and when that failed an interceptor) that
sets:
request.setAttribute("requestObject" , request);
but the best error I can get is:
freemarker.beans - Key 'requestObject' was not found on instance of
org.apache.struts2.dispatcher.StrutsRequestWrapper
How can I get access to the Request object inside of my Freemarker template
when I am using Struts 2?
--
View this message in context: http://www.nabble.com/Strus2%2C-Freemarker-and-getting-request.getContextPath%28%29-tp20032062p20032062.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by Adam Lister <al...@MIT.EDU>.
Sorry, should have read the original question more carefully!
> Because he provided JSP syntax (more accurate the OGNL syntax inside an S2 "property" tag in either JSP or FreeMarker). A plain %{expression} inside FreeMarker, IIRC, would be meaningless.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 10/17/08, doahh wrote:
> I have no idea why the mehtod you gave doesn't work for me [...]
Because he provided JSP syntax (more accurate the OGNL syntax inside an S2 "property" tag in either JSP or FreeMarker). A plain %{expression} inside FreeMarker, IIRC, would be meaningless.
Another FreeMarker page at [1] provides different names for the scopes; I don't know why the two docs aren't the same, or which is correct. You should also be able to access the values via the OGNL syntax inside an <@s.property...> FreeMarker "tag".
Dave
[1] http://struts.apache.org/2.x/docs/freemarker.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by doahh <ga...@prodia.co.uk>.
Thanks again for the reply, it didn't work for me but I managed to get it
thanks to the documentation you pointed me towards. I got it through:
${action.servletResponseFromActionContext.contextPath}
where 'servletResponseFromActionContext' is a method
'getServletResponseFromActionContext' of my action that returns the real
HttpServletRequest object. My method is:
public HttpServletResponse getServletResponseFromActionContext(){
ActionContext actionContext = ActionContext.getContext();
final HttpServletResponse response = (HttpServletResponse)
actionContext.get(StrutsStatics.HTTP_RESPONSE);
return response;
}
and your action must implement 'ServletResponseAware'.
I have no idea why the mehtod you gave doesn't work for me but I always got
the string printed out as plain text - odd as obviously I can use the
'action' parameter OK (I can also use the 'struts' parameter).
--
View this message in context: http://www.nabble.com/Re%3A-Strus2%2C-Freemarker-and-getting-request.getContextPath%28%29-tp20032257p20037248.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by Adam Lister <al...@MIT.EDU>.
%{#request}
That should get you the request context, as stated in:
http://struts.apache.org/2.x/docs/ognl.html
doahh wrote:
> Thanks for the reply, I am sure I am being dumb but I haven't had any luck in
> getting them working. I have tried:
>
> ${req}
> ${#req}
> %{req}
> %{#req}
>
> can you give an example of the correct syntax please?
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by doahh <ga...@prodia.co.uk>.
Thanks for the reply, I am sure I am being dumb but I haven't had any luck in
getting them working. I have tried:
${req}
${#req}
%{req}
%{#req}
can you give an example of the correct syntax please?
--
View this message in context: http://www.nabble.com/Re%3A-Strus2%2C-Freemarker-and-getting-request.getContextPath%28%29-tp20032257p20035357.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strus2, Freemarker and getting request.getContextPath()
Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 10/17/08, doahh wrote:
> How can I get access to the Request object inside of my
> Freemarker template when I am using Struts 2?
http://struts.apache.org/2.x/docs/freemarker-support.html
Towards the top, under the "Objects in the Context" is.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org