You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by R <bi...@gmail.com> on 2016/10/17 16:59:22 UTC
Is UTF-8 used everywhere for Tomcat 8.5.6?
Hi,
I have a default installation of Tomcat 8.5.6. When I make a POST request
with a tilde character, and the encoding is set to UTF-8, it seems that my
servlet handler is decoding it incorrectly. I have to set the character
encoding on the HttpServletRequest parameter to decode properly, example:
protected void doPost(HttpServletRequest request, ...) {
// I have to set this manually.
request.setCharacterEncoding("UTF-8");
// Decoding works now.
String test = request.getParam("test");
...
}
Reading the Tomcat docs, it seems like everything should be UTF-8 by
default. Is there a setting we still have to apply to get UTF-8 to be the
default encoding?
Thanks
Re: Is UTF-8 used everywhere for Tomcat 8.5.6?
Posted by Konstantin Kolinko <kn...@gmail.com>.
/2016-10-17 19:59 GMT+03:00 R <bi...@gmail.com>:
> Hi,
>
> I have a default installation of Tomcat 8.5.6. When I make a POST request
> with a tilde character, and the encoding is set to UTF-8, it seems that my
> servlet handler is decoding it incorrectly. I have to set the character
> encoding on the HttpServletRequest parameter to decode properly, example:
>
> protected void doPost(HttpServletRequest request, ...) {
> // I have to set this manually.
> request.setCharacterEncoding("UTF-8");
>
> // Decoding works now.
> String test = request.getParam("test");
> ...
> }
>
> Reading the Tomcat docs, it seems like everything should be UTF-8 by
> default. Is there a setting we still have to apply to get UTF-8 to be the
> default encoding?
For GET requests it defaults to UTF-8 (though actually it depends on
STRICT_SERVLET_COMPLIANCE setting. I prefer to explicitly configure
URIEncoding="UTF-8" on a Connector).
For POST requests you need to use
"org.apache.catalina.filters.SetCharacterEncodingFilter" filter (or a
similar 3-rd party filter e.g. the one provided by Spring Framework)
that essentially calls request.setCharacterEncoding() for you.
See webapps/examples/WEB-INF/web.xml for an example.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Is UTF-8 used everywhere for Tomcat 8.5.6?
Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2016 17:59, R wrote:
> Hi,
>
> I have a default installation of Tomcat 8.5.6. When I make a POST request
> with a tilde character, and the encoding is set to UTF-8, it seems that my
> servlet handler is decoding it incorrectly.
The tilde character should not need to be encoded. The byte sequence is
also identical between UTF-8, ISO-8859-1 and ASCII.
You'll need to be more specific about exactly what URL you are passing
to Tomcat.
> I have to set the character
> encoding on the HttpServletRequest parameter to decode properly, example:
>
> protected void doPost(HttpServletRequest request, ...) {
> // I have to set this manually.
> request.setCharacterEncoding("UTF-8");
>
> // Decoding works now.
> String test = request.getParam("test");
> ...
> }
>
> Reading the Tomcat docs, it seems like everything should be UTF-8 by
> default. Is there a setting we still have to apply to get UTF-8 to be the
> default encoding?
No. Tomcat 8.5.x uses UTF-8 by default.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org