tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ake Tangkannaond" <>
Subject RE: UTF-8 encoding in Tomcat 6.0
Date Wed, 21 Apr 2010 11:13:18 GMT
Where do you see the recommendation of using filter to handle utf8 char encoding in GET ?


-----Original Message-----
From: Mircea LUTIC [] 
Sent: Wednesday, April 21, 2010 5:57 PM
To: Tomcat Users List
Subject: Re: UTF-8 encoding in Tomcat 6.0

The filter does get called on my GET request.
In my understanding, a filter is the reccomended method of handling UTF-8 for both GET &
POST (as well as other methods like HEAD, PUT etc.).

When the request is "test.jsp?Name=larevolu%C8%9Bie" as in the example page
the EncodingFilter.doFilter function is being called and it calls 
the EncodingFilter.check function as below

        if (Name!=null)
            check(Name, lang);

and the String Name is incorrect as mentionned in the comment below:

void check(String Name, java.util.Locale lang)
    int c8=Name.codePointAt(8);//c8=200=C8 // should be 539=21Bh = ț
    int c9=Name.codePointAt(9);//c9=155=9B // should be 105= 69h = i
    char ch[]={Name.charAt(8),Name.charAt(9)};
    int x=c8+c9;    //to have eclipse (Galileo) display the above
    String s=new String(ch); 

server.xml contains the following:

    <Connector port="8060" protocol="HTTP/1.1" 
               redirectPort="8443" URIEncoding="UTF-8"  /> 

This is because my tomcat 6 is set to work on 8060 with no redirect because this is a debug
(some time ago I also had tomcat 5 on 8050 but at that time I didn't check the UTF-8 issue)
Thanks for you help.

From: Ake Tangkannaond <>
To: Tomcat Users List <>
Sent: Wed, 21 April, 2010 12:42:36
Subject: RE: UTF-8 encoding in Tomcat 6.0

Hi Mircea,

That filter you wrote is for POST and it has nothing to do with GET request.

Have you check the documentation on the conf/server.xml on the following line?

    <Connector port="8080" protocol="HTTP/1.1" 


               redirectPort="8443" URIEncoding="UTF-8"/>


From: Mircea LUTIC [] 
Sent: Wednesday, April 21, 2010 3:40 PM
Subject: UTF-8 encoding in Tomcat 6.0


I'm having trouble convincing tomcat 6.0 to take UTF-8 strings.
I created an encoding filter with no luck. 

    Here is the Utf8 Filter that fails for me in 
Tomcat 6.0.20 / Eclipse-Galileo / Windows Vista (6.0.6002) <---> Firefox 3.6.3.
        java version "1.6.0_20"
        Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
        Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
    Everything is on my  laptop (http://localhost:8060).
    What I do is create a GET string (based on parameters from a showModalDialog)
    by script and send it (from Firefox) to the (localhost) server 
    which is running under eclipse with a breakpoint in the EncodingFilter.
    Note that the system locale is ro_RO (may have an influence)

* set in appl/WebContent/web.xml:

* set in tomcat/conf/server.xml at <Connector protocol="HTTP/1.1


public class EncodingFilter implements Filter 
    private String encoding;
    private FilterConfig filterConfig;
    public EncodingFilter() {}
    public void destroy() {}

    public void init(FilterConfig fc) throws ServletException 
        this.filterConfig = fc;
        this.encoding = filterConfig.getInitParameter("encoding");
    public void doFilter
        (ServletRequest  request
        ,ServletResponse response
        , FilterChain chain
        ) throws IOException, ServletException 
        String clientEncoding=request.getCharacterEncoding();
        String Name;

        String fileEncoding=System.getProperty("file.encoding");
        if (fileEncoding==null || !fileEncoding.equals("UTF-8"))// eclipse says it's already
            System.setProperty("file.encoding", "UTF-8");    // so this never gets executed
        if(null == clientEncoding)    // this is always null
             request.setCharacterEncoding(encoding);// so this is always set
        //String uri=request instanceof HttpServletRequest?((HttpServletRequest)request).getRequestURI():null;if
        // using alert(scriptCreatedUrl) I can see that
        // GET sent Name=revoluție as Name=revolu%C8%9Bie (correct) 
        if (Name!=null)
            java.util.Locale lang=request.getLocale();//ro_RO
            check(Name, lang);
            check("larevoluție"   , lang);// these are ok
            check("_el_piraña"    , lang);
            check("_qi_gong气功"  , lang);
            check("_psyche_ψυχή"  , lang);
            check("_shalom_שָׁלוֹם"  , lang);
            check("_salaam_سَلاَمٌ"   , lang);
            check("_Baikal_Байка́л", lang);

        chain.doFilter(request, response);
    void check(String Name, java.util.Locale lang)
        int c8=Name.codePointAt(8);//c6=200=C8 // should be 539=21Bh = ț
        int c9=Name.codePointAt(9);//c7=155=9B // should be 105= 69h = i
        char ch[]={Name.charAt(8),Name.charAt(9)};
        int x=c8+c9;    //to have eclipse (Galileo) display the above
        String s=new String(ch); 
*     also typed "about:config" in the (Firefox) address bar.
    Used the filter input to search for "network.standard-url.encode-query-utf8" property.
    turned it to true & restarted the browser: no luck

Here is also a page that sends a failing request:

<%@ page language="java"
    contentType="text/html; charset=UTF-8"
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
function send()
<button onclick="send()">send</button>

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message