You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Srinivas.N." <ns...@yahoo.com> on 2008/02/11 21:20:06 UTC

Not escaping '&' when passing urls as http params

When I pass URLs as parameters, is there a way to not html escape the '&'
characters?

Example: Lets say I have a JSP where I want to pass a URL as a param within
another URL. Example:

Some JSP
---------

<!-- Get the current URL -->
<s:url id="currentUrl" includeParams="get"/>

<!-- Construct a new url passing the current URL as the backLink" -->
<s:url id="newUrl" action="newAction">
  <s:param name="backLink" value="%{currentUrl}"/>
</s:url>

Lets say current URL is something like http://mydomain/action1?p1=1&p2=2

The problem is that when newUrl is constructed, struts2 is escaping the '&'
character in the URL. So, the backLink says p1=1 & amp ;p2=2 instead of
p1=1&p2=2 (note: i put the spaces between & amp and ; just for clarity here
so that this editor doesnt convert it to a '&') . This is preventing the
parameter p2 from being parsed correctly when that URL is requested.

Is there an escape property on s:url like the one on <s:property> ? Any
workarounds?

Thanks
SN

-- 
View this message in context: http://www.nabble.com/Not-escaping-%27-%27-when-passing-urls-as-http-params-tp15419699p15419699.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: Not escaping '&' when passing urls as http params

Posted by "Srinivas.N." <ns...@yahoo.com>.
You are right. In my JSP for newUrl in my example, I was using <s:property
value="#parameters.backLink"/> and that was escaping th '&' once again I
think. Now, I changed that to <s:property value="#parameters.backLink"
escape="false"/> and that works. Thanks!

- SN



Laurie Harper wrote:
> 
> Srinivas.N. wrote:
>> When I pass URLs as parameters, is there a way to not html escape the '&'
>> characters?
>> 
>> Example: Lets say I have a JSP where I want to pass a URL as a param
>> within
>> another URL. Example:
>> 
>> Some JSP
>> ---------
>> 
>> <!-- Get the current URL -->
>> <s:url id="currentUrl" includeParams="get"/>
>> 
>> <!-- Construct a new url passing the current URL as the backLink" -->
>> <s:url id="newUrl" action="newAction">
>>   <s:param name="backLink" value="%{currentUrl}"/>
>> </s:url>
>> 
>> Lets say current URL is something like http://mydomain/action1?p1=1&p2=2
>> 
>> The problem is that when newUrl is constructed, struts2 is escaping the
>> '&'
>> character in the URL. So, the backLink says p1=1 & amp ;p2=2 instead of
>> p1=1&p2=2 (note: i put the spaces between & amp and ; just for clarity
>> here
>> so that this editor doesnt convert it to a '&') . This is preventing the
>> parameter p2 from being parsed correctly when that URL is requested.
>> 
>> Is there an escape property on s:url like the one on <s:property> ? Any
>> workarounds?
> 
> Not really; the behaviour you're seeing is correct. You absolutely want 
> that escaping to happen, otherwise newUrl would be an invalid/malformed 
> URL. The backLink parameter should be un-escaped again by the time you 
> retrieve its value, so the problem you're having probably lies elsewhere.
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Not-escaping-%27-%27-when-passing-urls-as-http-params-tp15419699p15421391.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: Not escaping '&' when passing urls as http params

Posted by Laurie Harper <la...@holoweb.net>.
Srinivas.N. wrote:
> When I pass URLs as parameters, is there a way to not html escape the '&'
> characters?
> 
> Example: Lets say I have a JSP where I want to pass a URL as a param within
> another URL. Example:
> 
> Some JSP
> ---------
> 
> <!-- Get the current URL -->
> <s:url id="currentUrl" includeParams="get"/>
> 
> <!-- Construct a new url passing the current URL as the backLink" -->
> <s:url id="newUrl" action="newAction">
>   <s:param name="backLink" value="%{currentUrl}"/>
> </s:url>
> 
> Lets say current URL is something like http://mydomain/action1?p1=1&p2=2
> 
> The problem is that when newUrl is constructed, struts2 is escaping the '&'
> character in the URL. So, the backLink says p1=1 & amp ;p2=2 instead of
> p1=1&p2=2 (note: i put the spaces between & amp and ; just for clarity here
> so that this editor doesnt convert it to a '&') . This is preventing the
> parameter p2 from being parsed correctly when that URL is requested.
> 
> Is there an escape property on s:url like the one on <s:property> ? Any
> workarounds?

Not really; the behaviour you're seeing is correct. You absolutely want 
that escaping to happen, otherwise newUrl would be an invalid/malformed 
URL. The backLink parameter should be un-escaped again by the time you 
retrieve its value, so the problem you're having probably lies elsewhere.

L.


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


Re: Not escaping '&' when passing urls as http params

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
<s:url/> has an attribute called escapeAmp (default = true) that may 
assist you.

http://struts.apache.org/2.0.11/docs/url.html

Srinivas.N. wrote:
> When I pass URLs as parameters, is there a way to not html escape the '&'
> characters?
>
> Example: Lets say I have a JSP where I want to pass a URL as a param within
> another URL. Example:
>
> Some JSP
> ---------
>
> <!-- Get the current URL -->
> <s:url id="currentUrl" includeParams="get"/>
>
> <!-- Construct a new url passing the current URL as the backLink" -->
> <s:url id="newUrl" action="newAction">
>   <s:param name="backLink" value="%{currentUrl}"/>
> </s:url>
>
> Lets say current URL is something like http://mydomain/action1?p1=1&p2=2
>
> The problem is that when newUrl is constructed, struts2 is escaping the '&'
> character in the URL. So, the backLink says p1=1 & amp ;p2=2 instead of
> p1=1&p2=2 (note: i put the spaces between & amp and ; just for clarity here
> so that this editor doesnt convert it to a '&') . This is preventing the
> parameter p2 from being parsed correctly when that URL is requested.
>
> Is there an escape property on s:url like the one on <s:property> ? Any
> workarounds?
>
> Thanks
> SN
>
>   


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