On Thursday 12 March 2009 23:34:22 Daniel Ruan wrote:
> Has anyone used the UrlRewriter outbound rules with Struts 2?
> UrlRewriter requires that the urls go through response.encodeURL().
> In JSP and JSTL examples:
>
> <a href="<%= response.encodeURL("/world.jsp?country=usa&amp;city=nyc")
> %>">nyc</a>
>
> <a href="<c:url value="/world.jsp?country=${country}&amp;city=${city}"
> />">nyc</a>
>
> What is the Struts2 equivalent way?  (s:url encode="true" does not work).
>
> Thanks,
>

I'm not sure if I'm answering your question, but the struts2 way would differ 
slightly from your example in two ways - 

1. world.jsp should be converted to an action rather than a JSP. You could 
simple map world.jsp to ActionSupport if you didn't want to code a whole 
action, but since your taking parameters, I would suggest writing an action 
for it.

2. Rather than using a scriptlet, you'd use the struts2 tags to generate the 
link. This could be done in a few ways - 

2a. generate the url with the s:url tag and assign it to a variable on the 
value stack to use with the s:a tag - 
<s:url var="theLink" action="world" namespace="/whatever"><s:param 
name=country value="whatever"/><s:param name="city" value="whatever"/></s:url>
<s:a href="#theLink">nyc</s:a>

2b. use the s:url tag right in the href= of your HTML a tag -
<a href="<s:url action="world" namespace="/whatever"><s:param ...

2c. If possible, use the recently committed (today) version of s:a -
<s:a action="world" namespace="/whatever"><s:param ...

Again, I'm not sure if I'm answering your question, but I know one of the 
reasons I use Struts is to avoid adding scriptlets. 

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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

Reply via email to