2 Replies Latest reply on Feb 7, 2007 2:23 AM by xiao lv

    How to set Character Encoding correctly?

    Scott Wang Newbie

      Hi,anybody help me

      I write two jsp files. Content as following:
      a.jsp
      ------------------------------------------------

      <%@ page language="java" contentType="text/html; charset=UTF-8"%>
      <html>
       <HEAD>
       <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
       </HEAD>
       <body>
       <script language="javascript">
       function _goto(){
       location.href=encodeURI("b.jsp?names=??");
       }
       </script>
       </body>
      </html>


      b.jsp
      ------------------------------------------------------------------
      <%@ page language="java" contentType="text/html; charset=UTF-8"%>
      <html>
       <HEAD>
       <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
       </HEAD>
       <body>
       <%
       request.setCharacterEncoding("UTF-8");
       String names = request.getParameter("names");
       System.out.println("Names:"+names);
       %>
       </body>
      </html>


      following is configuration:
      jbossweb-tomcat50.sar/server.xml

      <Service name="jboss.web" className="org.jboss.web.tomcat.tc5.StandardService">
       <Connector useBodyEncodingForURI="true" URIEncoding="UTF-8"/>
      


      Console print:
      Names:????????????

      While I set 'useBodyEncodingForURI' to false,Console print is OK:
      Names:??

      why? what is real meaning of 'useBodyEncodingForURI=true'.

        • 1. Re: How to set Character Encoding correctly?
          Scott Wang Newbie

          b.jsp?names=??

          ?? is chinese character.

          Anybody help? thanks.

          • 2. Re: How to set Character Encoding correctly?
            xiao lv Newbie

            your setting i think is right.

            but location.href=encodeURI("b.jsp?names=??");

            why you need to encode. i think:

            location.href="b.jsp?names=??";


            can be OK.


            "spec_third" wrote:
            Hi,anybody help me

            I write two jsp files. Content as following:
            a.jsp
            ------------------------------------------------
            <%@ page language="java" contentType="text/html; charset=UTF-8"%>
            <html>
             <HEAD>
             <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
             </HEAD>
             <body>
             <script language="javascript">
             function _goto(){
             location.href=encodeURI("b.jsp?names=??");
             }
             </script>
             </body>
            </html>


            b.jsp
            ------------------------------------------------------------------
            <%@ page language="java" contentType="text/html; charset=UTF-8"%>
            <html>
             <HEAD>
             <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
             </HEAD>
             <body>
             <%
             request.setCharacterEncoding("UTF-8");
             String names = request.getParameter("names");
             System.out.println("Names:"+names);
             %>
             </body>
            </html>


            following is configuration:
            jbossweb-tomcat50.sar/server.xml

            <Service name="jboss.web" className="org.jboss.web.tomcat.tc5.StandardService">
             <Connector useBodyEncodingForURI="true" URIEncoding="UTF-8"/>
            


            Console print:
            Names:????????????

            While I set 'useBodyEncodingForURI' to false,Console print is OK:
            Names:??

            why? what is real meaning of 'useBodyEncodingForURI=true'.