...
Permalink to this page: https://cwiki.apache.org/confluence/x/liklBg
Questions
- Why
- How
- How do I change how GET parameters are interpreted?
- How do I change how POST parameters are interpreted?
- What can you recommend to just make everything work? (How to use UTF-8 everywhere).
- How can I test if my configuration will work correctly?
- How can I send higher characters in HTTP headers?
- How to configure the BASIC authentication scheme to use UTF-8
- Troubleshooting
Answers
Why
Anchor | ||||
---|---|---|---|---|
|
...
- Set
URIEncoding="UTF-8"
on your <Connector> inserver.xml
. References: Tomcat 7 HTTP Connector, Tomcat 7 AJP Connector, Tomcat 8.5 HTTP Connector, Tomcat 8.5 AJP Connector. - Set the default request character encoding either in the Tomcat
conf/web.xml
file or in the web appweb.xml
file; either by setting<request-character-encoding>
(for applications using Servlet 4.0 / Tomcat 9.x+) or by using a character encoding filter. - Change all your JSPs to include charset name in their contentType. For example, use
<%@page contentType="text/html; charset=UTF-8" %>
for the usual JSP pages and<jsp:directive.page contentType="text/html; charset=UTF-8" />
for the pages in XML syntax (aka JSP Documents). - Change all your servlets to set the content type for responses and to include charset name in the content type to be UTF-8. Use
response.setContentType("text/html; charset=UTF-8")
orresponse.setCharacterEncoding("UTF-8")
. - Change any content-generation libraries you use (Velocity, Freemarker, etc.) to use UTF-8 and to specify UTF-8 in the content type of the responses that they generate.
- Disable any valves or filters that may read request parameters before your character encoding filter or jsp page has a chance to set the encoding to UTF-8. For more information see https://www.mail-archive.com/users@tomcat.apache.org/msg21117.html.
...
You have to encode them in some way before you insert them into a header. Using url-encoding (%
+ high byte number + low byte number) would be a good idea.
Anchor | ||||
---|---|---|---|---|
|
If a web application is configured to use the BASIC authentication scheme (e.g. configured with <auth-method>BASIC</auth-method>
in its web.xml file), it means that an instance of BasicAuthenticator will be automatically created and inserted into the chain of Valves for this web application (this Context), unless any other Authenticator valve has already been explicitly configured.
To enable support for UTF-8 in a BasicAuthenticator, you can configure it explicitly, by inserting the following line into the Context configuration file of your web application (usually META-INF/context.xml):
<Valve className="org.apache.catalina.authenticator.BasicAuthenticator" charset="UTF-8" />
If you do so, the BasicAuthenticator will append "charset=UTF-8" to the value of WWW-Authenticate header that it sends and will interpret the values sent by clients as UTF-8.
See also:
- Configuration Reference (Tomcat 9): Valves (Authentication), Context (Defining a context).
- Bug 61280
- Bug 66174
- Specifications (RFC 7617)
Troubleshooting
Anchor | ||||
---|---|---|---|---|
|
...