tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ake Tangkannaond" <iam...@gmail.com>
Subject RE: UTF-8 encoding in Tomcat 6.0
Date Wed, 21 Apr 2010 09:42:36 GMT
Hi Mircea,

=20

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

=20

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

    <Connector port=3D"8080" protocol=3D"HTTP/1.1"=20

               connectionTimeout=3D"20000"=20

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

=20

=20

-Ake

=20

From: Mircea LUTIC [mailto:mircea_lutic@yahoo.com]=20
Sent: Wednesday, April 21, 2010 3:40 PM
To: users@tomcat.apache.org
Subject: UTF-8 encoding in Tomcat 6.0

=20

Hello,


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

/**
    Here is the Utf8 Filter that fails for me in=20
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).
   =20
    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=20
    which is running under eclipse with a breakpoint in the =
EncodingFilter.
   =20
    Note that the system locale is ro_RO (may have an influence)

 *=20
 * set in appl/WebContent/web.xml:
 *=20
 <filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>ro.lutic.transcode.EncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

 *=20
 * set in tomcat/conf/server.xml at <Connector protocol=3D"HTTP/1.1
 *=20
    URIEncoding=3D"UTF-8"  =20

 */


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

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

        String fileEncoding=3DSystem.getProperty("file.encoding");
        if (fileEncoding=3D=3Dnull || !fileEncoding.equals("UTF-8"))// =
eclipse says it's already UTF-8
            System.setProperty("file.encoding", "UTF-8");    // so this =
never gets executed
       =20
        if(null =3D=3D clientEncoding)    // this is always null
             request.setCharacterEncoding(encoding);// so this is always =
set
            =20
        //String uri=3Drequest instanceof =
HttpServletRequest?((HttpServletRequest)request).getRequestURI():null;if =
(uri!=3Dnull)uri+=3D"";
        //window.location=3DscriptCreatedUrl;
        // using alert(scriptCreatedUrl) I can see that
        // GET sent Name=3Drevolu=C8=9Bie as Name=3Drevolu%C8%9Bie =
(correct)=20
       =20
        Name=3Drequest.getParameter("Name");
        if (Name!=3Dnull)
        {
            java.util.Locale lang=3Drequest.getLocale();//ro_RO
            check(Name, lang);
               =20
            check("larevolu=C8=9Bie"   , lang);// these are ok
            check("_el_pira=C3=B1a"    , lang);
            check("_qi_gong=E6=B0=94=E5=8A=9F"  , lang);
            check("_psyche_=CF=88=CF=85=CF=87=CE=AE"  , lang);
            check("_shalom_=D7=A9=D6=B8=D7=81=D7=9C=D7=95=D6=B9=D7=9D"  =
, lang);
            check("_salaam_=D8=B3=D9=8E=D9=84=D8=A7=D9=8E=D9=85=D9=8C"   =
, lang);
            check("_Baikal_=D0=91=D0=B0=D0=B9=D0=BA=D0=B0=CC=81=D0=BB", =
lang);
        }

        chain.doFilter(request, response);
    }
    void check(String Name, java.util.Locale lang)
    {
        int c8=3DName.codePointAt(8);//c6=3D200=3DC8 // should be =
539=3D21Bh =3D =C8=9B
        int c9=3DName.codePointAt(9);//c7=3D155=3D9B // should be 105=3D =
69h =3D i
        char ch[]=3D{Name.charAt(8),Name.charAt(9)};
        int x=3Dc8+c9;    //to have eclipse (Galileo) display the above
        String s=3Dnew String(ch);=20
    }
}
/*
 *     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=3D"java"
    pageEncoding=3D"UTF-8"=20
    contentType=3D"text/html; charset=3DUTF-8"
 %>

http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3DUTF-8">
<title>UTF-8</title>
<script>
function send()
{
    =
window.location=3D"test.jsp?Name=3Dlarevolu%C8%9Bie";//"test.jsp?Name=3D"=
+escape(Utf8encode("larevolu=C8=9Bie"))
}
</script>
</head>
<body>
<button onclick=3D"send()">send</button>
</body>
</html>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message