tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Hook" <hoo...@hotmail.com>
Subject Re: Tomcat5.0.28 character encodingg problem
Date Wed, 25 Jul 2007 18:12:32 GMT
Both Chris and Tim are giving great advice.  We're actually just trying to 
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 
following:

<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 the 
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.  I 
would recommend placing that as the very first filter that gets called in 
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 this 
time.  My guess is doing
     // the null checks because from my understanding the client can change 
the page encoding on
     // each and every request even though the server sets the page up to be 
utf-8.
     request = (HttpServletRequest)request;
     request.setCharacterEncoding("UTF-8");

     // 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.
     response.setCharacterEncoding("UTF-8");
     // Set the content type in the header of the response.
     response.setContentType("text/html;charset=UTF-8");

     filterChain.doFilter(request, response);
  }
}


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

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


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

In mysql you add the following to your jdbc url connection string:
useUnicode=true
characterEncoding=UTF-8


I hope all that information helps.


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

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

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

-Tim

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 and
>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
>solution.
>
>My questions are:  Does Tomcat have problems with any types of encoding?    
>   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: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

_________________________________________________________________
http://newlivehotmail.com


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message