You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niall Pemberton <ni...@gmail.com> on 2007/06/01 15:07:21 UTC

Re: Struts 1.2.9 and UNICODE issue on form submittal

On 5/29/07, Adam Gordon <ad...@readytalk.com> wrote:
> We're using the html:form element and we have the acceptCharset
> attribute set to "UTF-8" and when we enter a unicode character in a
> textarea in this form element, the UTF-8 character (in this case \u2022,
> the bullet symbol:  •) displays correctly.  However, when the form is
> submitted, I'm printing out the bean property for this textarea and I'm
> finding that Struts has broken up the UNICODE character into 3 separate
> characters:  •.
>
> We have the Content-Type meta tag set to the UTF-8 charset on the JSP
> and we've set the @page directive for contentType also to "text/html;
> charset=UTF-8".  We've found a workaround, but it's totally a hack as we
> basically remove all encodings and then reconstruct the string from a
> byte array.
>
> Anyone have an idea as to what might be going on and why Struts appears
> to be mucking with the encoding?  Thanks.

Struts doesn't do anything with the encoding - I imagine if you
accessed the parameter value directly from the request you will see
the same issue. You could try setting the encoding on the request
using the setCharacterEncoding("UTF-8") - but you need to do that
before the request is processed - (either in the request processor in
Struts 1.2.x or inserting a Command into the chain for 1.3.x)

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/WebI18N5.html

If that doesn't work then I would look at the Servlet Container you're
using - for example Tomcat has the following FAQ:

http://tomcat.apache.org/faq/misc.html#tomcat5CharEncoding

Niall

> --adam

Re: Struts 1.2.9 and UNICODE issue on form submittal

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Adam,

Adam Gordon wrote:
> After some digging, there's  URIEncoding attribute on the Connector
> element that if not specified defaults to ISO-8859-1 when attempting to
> decode URI bytes.  I suspect setting this to UTF-8, in addition to the
> other changes we made (the @page directive and <meta> tag directive for
> the Content-Type, and the acceptCharset attribute on html:form all to
> UTF-8) will fix the problem...we'll see.

Unless you posted inaccurate information in the past, this is not the
problem.

The URIEncoding attribute only sets the character encoding for the URI
submitted in the HTTP method line (i.e. "GET /foo/bar/baz" or "POST
/foo/bar/baz").

Since you said you were using POST, there should be no form data in the
method portion of the request. The body of an HTTP request ought to be
interpreted using the Content-Type header provided with the request. The
interpretation of the request body will not change regardless of the
URIEncoding attribute value.

> After reading some of the developer comments in the filed bugs, UTF-8
> appears to be the only standard on URL encoding, however according to
> them in 2003, no one really paid attention it - hopefully this is not
> the case anymore.

If you want to accept non-latin1 characters, you should set /everything/
to UTF-8.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGYGN79CaO5/Lv0PARAmOmAJ48hwaT5BDW5/BkNNNvYmLQUNFl/QCfUnTL
dUiSuB1P+mTbfrcuhca1CIA=
=3/Ir
-----END PGP SIGNATURE-----

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


Re: Struts 1.2.9 and UNICODE issue on form submittal

Posted by Adam Gordon <ad...@readytalk.com>.
You know, I had my doubts about whether or not Struts was really 
actually doing anything with POST request parameters other than just 
reading them.  It did seem to me that it was more of an issue at the 
Tomcat level since Tomcat is the one serving up the parameters.

After some digging, there's  URIEncoding attribute on the Connector 
element that if not specified defaults to ISO-8859-1 when attempting to 
decode URI bytes.  I suspect setting this to UTF-8, in addition to the 
other changes we made (the @page directive and <meta> tag directive for 
the Content-Type, and the acceptCharset attribute on html:form all to 
UTF-8) will fix the problem...we'll see.

After reading some of the developer comments in the filed bugs, UTF-8 
appears to be the only standard on URL encoding, however according to 
them in 2003, no one really paid attention it - hopefully this is not 
the case anymore.

Thanks for the reference links.

--adam

Niall Pemberton wrote:
> Struts doesn't do anything with the encoding - I imagine if you
> accessed the parameter value directly from the request you will see
> the same issue. You could try setting the encoding on the request
> using the setCharacterEncoding("UTF-8") - but you need to do that
> before the request is processed - (either in the request processor in
> Struts 1.2.x or inserting a Command into the chain for 1.3.x)
>
> http://java.sun.com/j2ee/1.4/docs/tutorial/doc/WebI18N5.html
>
> If that doesn't work then I would look at the Servlet Container you're
> using - for example Tomcat has the following FAQ:
>
> http://tomcat.apache.org/faq/misc.html#tomcat5CharEncoding
>
> Niall

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