Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
character encodingg problem

character encodingg problem

2007-08-13       - By Russo, Joe

 Back
Reply:     1     2     3     4  

Hi,
This information you provided helped me a lot.  I was able to include
the filter and get the correct data.  The main problem I am having is
the current data is basically corrupt.

This is what I believe is happening:  some of the data is having the
wrong character encoding into the database and causes those funky
characters.  If I include the filter it does work with the existing data
being encoded properly and no bad or correct data is put into the DB.

Of course, the existing data that is stored incorrectly can not be
viewed correctly.  I thought by changing the filter you sent by
interrupting the charset as ISO-8859 (See http://ISO-8859.ora-code.com)-1 for the response would work
correctly.  This would be great if it work that it would have all new
data put in correctly and all the old data would be seen correctly.

Any ideas or help would be appreciated.
Joe

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;

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{
   request = (HttpServletRequest)request;
   request.setCharacterEncoding("UTF-8 (See http://UTF-8.ora-code.com)");
   response.setCharacterEncoding("ISO-8859 (See http://ISO-8859.ora-code.com)-1");
   response.setContentType("text/html;charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1");

   filterChain.doFilter(request, response);
 }
}


-- --Original Message-- --
From: Nathan Hook [mailto:hooknc@(protected)]
Sent: Wednesday, July 25, 2007 2:13 PM
To: users@(protected)
Subject: Re: Tomcat5.0.28 character encodingg problem

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 (See http://UTF-8.ora-code.com)" />


- 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 (See http://utf-8.ora-code.com).  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 (See http://utf-8.ora-code.com).
    request = (HttpServletRequest)request;
    request.setCharacterEncoding("UTF-8 (See http://UTF-8.ora-code.com)");

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

    filterChain.doFilter(request, response);
 }
}


- Set the meta type in each and every jsp to be utf-8 (See http://utf-8.ora-code.com).  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 (See http://utf-8.ora-code.com)" />
</head>


- Finally for database storage...  Again from my understanding you will
need
to set all your tables to utf-8 (See http://utf-8.ora-code.com) and then inform your JDBC Driver that
you
want to pass everything back and forth using utf-8 (See http://utf-8.ora-code.com).

In mysql you add the following to your jdbc url connection string:
useUnicode=true
characterEncoding=UTF-8 (See http://UTF-8.ora-code.com)


I hope all that information helps.


----Original Message Follows----
From: Tim Funk <funkman@(protected)>
Reply-To: "Tomcat Users List" <users@(protected)>
To: Tomcat Users List <users@(protected)>
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 (See http://UTF-8.ora-code.com)" .../>

-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 (See http://UTF-8.ora-code.com) 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@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
http://newlivehotmail.com


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.