Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add a recipe on how to configura a BasicAuthenticator to use UTF-8

...

  1. Why
    1. What is the default character encoding of the request or response body?
    2. Why does everything have to be this way?
  2. How
    1. How do I change how GET parameters are interpreted?
    2. How do I change how POST parameters are interpreted?
    3. What can you recommend to just make everything work? (How to use UTF-8 everywhere).
    4. How can I test if my configuration will work correctly?
    5. How can I send higher characters in HTTP headers?
    6. How to configure the BASIC authentication scheme to use UTF-8
  3. Troubleshooting
    1. I'm having a problem with character encoding in Tomcat 5

...

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
Q10
Q10
How to configure the BASIC authentication scheme to use UTF-8

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:

Troubleshooting

Anchor
Q5
Q5
I'm having a problem with character encoding in Tomcat 5

...