tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Russo, Joe" <>
Subject RE: Tomcat5.0.28 character encodingg problem
Date Wed, 25 Jul 2007 18:50:25 GMT
I want to thank Chris, Tim, and Nathan for your advice.  I will try the
suggestions and use it to come up with a solution hopefully.
Thanks again.

-----Original Message-----
From: Nathan Hook [] 
Sent: Wednesday, July 25, 2007 2:13 PM
Subject: Re: Tomcat5.0.28 character encodingg problem

Both Chris and Tim are giving great advice.  We're actually just trying
internationalize our application for our next major release.

Here are the things we've learned.

- You have to change the URIEncoding on your Tomcat Connector in your 
server.xml (as Tim pointed out).

We are using mod_jk and had to change our entry in the server.xml to the


<Connector port="8009"
           enableLookups="false" redirectPort="8443" protocol="AJP/1.3" 
URIEncoding="UTF-8" />

- On every request that comes into your tomcat server you have to check
character encoding of your request and your response BEFORE any work is 
actually done.

So like Chris mentioned you want to look up a character encoding filter.
would recommend placing that as the very first filter that gets called
your application.  To do make this filter first in the filter chain is 
simple.  When adding your filter to your applications web.xml file, make

sure is the first one listed in the filter mappings section.

Here is the Filter we are currently using for testing.

public class ContentTypeFilter implements Filter {
  public void init(FilterConfig config) {}
  public void destroy() {}
  public void doFilter(ServletRequest request, ServletResponse response,

FilterChain filterChain) throws IOException, ServletException
     // I've seen some other classes that check to see if the character 
encoding is null and then set
     // the character encoding to utf-8.  I'm not sure which is best at
time.  My guess is doing
     // the null checks because from my understanding the client can
the page encoding on
     // each and every request even though the server sets the page up
to be 
     request = (HttpServletRequest)request;

     // Make sure to set the character encoding on the response early 
because once something is
     // sent back to the client (like a jsp), then the character
encoding is 
already set to the default
     // of the server.
     // Set the content type in the header of the response.

     filterChain.doFilter(request, response);

- Set the meta type in each and every jsp to be utf-8.  Now, most
will ignore this value from my understanding, but it shouldn't hurt to

  <title>test title</title>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

- Finally for database storage...  Again from my understanding you will
to set all your tables to utf-8 and then inform your JDBC Driver that
want to pass everything back and forth using utf-8.

In mysql you add the following to your jdbc url connection string:

I hope all that information helps.

----Original Message Follows----
From: Tim Funk <>
Reply-To: "Tomcat Users List" <>
To: Tomcat Users List <>
Subject: Re: Tomcat5.0.28 character encodingg problem
Date: Wed, 25 Jul 2007 12:09:07 -0400

And you should first start with in server.xml:
     <Connector ... URIEncoding="UTF-8" .../>


Joe Russo wrote:
>I am getting the following error in the display of the JSP.  To give a
>little history, this application I am supporting, at the time the
>developers thought they needed to encode the characters to UTF-8 into
>our Oracle DB.  The developers were unaware they could have allowed the
>DB Driver convert it for us.  Therefore, we double encode going into
>out of the database.  Really stupid in hindsight.  Trying to clean the
>database up is another project we face.
>I am in the process of converting from using JRUN to Tomcat and I have
>ran into the problem where these funky symbols are displaying.  I can
>not find any stack traces that would explain or possibly clue into a
>My questions are:  Does Tomcat have problems with any types of
>   What type of characters are being displayed below and any advice in
>troubleshooting or solving this would be gratefully appreciated.

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message