You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Thibaudeau <pi...@gmail.com> on 2009/03/19 05:06:11 UTC
[S2] encode attribute of : correct encoding?
I fail to understand how to use the "encode" attribute of the <s:url>.
Here's an example that puzzles me... Let's try, alternately, to set
"encode" to "true" and "false". Here goes:
<s:url action="myAction" namespace="/" encode="true"><s:param
name="entityName">Élizabeth</s:param></s:url>
yields:
/myAction?entityName=%C3%83%C2%89lizabeth
while
<s:url action="myAction" namespace="/" encode="false"><s:param
name="entityName">Élizabeth</s:param></s:url>
yields
/myAction?entityName=%C3%83%C2%89lizabeth
which is exactly identical to the previously generated URL!
Therefore what is the point of the "encode" attribute?
Moreover, when 'myAction' retrieves the 'entityName' parameter, it
converts it to: "Ãlizabeth".
???
BTW, when Google encodes the query string "Élizabeth" (without the
quotes), it does so as:
http://www.google.com/search?q=%C9lizabeth
* * *
My setup:
Tomcat 6.0.16, Java1.6.0_11, Struts 2.1.6
<constant name="struts.i18n.encoding" value="UTF-8"/>
The JSP page where the <s:url> tag appears contains the following
lines (each in its proper place):
<%@ page contentType="text/html;charset=UTF-8" language="java"
pageEncoding="UTF-8" %>
<?xml version="1.0" encoding="UTF-8"?>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
I have a Tomcat encoding filter that sets each request's encoding to:
"text/html;charset=UTF-8"
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] encode attribute of : correct encoding?
Posted by Pierre Thibaudeau <pi...@gmail.com>.
I still haven't found an answer to my puzzlement about encoding
non-ASCII characters. I've come to the conclusion that this isn't
specifically a Struts2 problem (so, I'll probably post on
stackoverflow for enlightenment), but for completeness's sake, here
are a few observations that may puzzle (or puzzled) other Strutsers:
In the following examples, I'm always encoding the string "Élizabeth"
(first character is an uppercase e-acute), using
java.net.URLEncoder.encode("Élizabeth", encoding) with a different
encoding each time; then passing that encoded string in a URL
parameter (?foobar=encoded+string); then displaying said parameter in
JSP (with ${param.foobar}).
encoding name ==> URLEncoder.encode() ==> display in JSP:
UTF-8 ==> %C3%83%C2%89lizabeth ==> Élisabeth
UTF-16 ==> %FE%FF%00%C3%00%89lizabeth ==> þÿ�Ã�‰lisabeth
UTF-16LE ==> %C3%00%89%00lizabeth ==> Ã�‰�lisabeth
UTF-16BE ==> %00%C3%00%89lizabeth ==> �Ã�‰lisabeth
ISO-8859-1 ==> %C3%89lizabeth ==> Élizabeth
no encoding ==> %C3%3Flizabeth ==> Ã?lizabeth
Finally, as a reminder of my previous post, if I let <s:url> encode
the parameter:
==> %C3%89lizabeth ==> Ãlizabeth
(which is the least bad of the lot!)
All in all, the encoding that WOULD work (but which I cannot generate)
would be: %C9lizabeth ==> Élizabeth (!!!)
If anyone has a clue on what's happening here, I'd love to read about it! ;)
Those tests were conducted with the setup mentioned in the previous
post in this thread, i.e:
> Tomcat 6.0.16, Java1.6.0_11, Struts 2.1.6
> <constant name="struts.i18n.encoding" value="UTF-8"/>
>
> <%@ page contentType="text/html;charset=UTF-8" language="java"
> pageEncoding="UTF-8" %>
> <?xml version="1.0" encoding="UTF-8"?>
> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
>
> I have a Tomcat encoding filter that sets each request's encoding to:
> "text/html;charset=UTF-8"
Firefox 3
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org