You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Antony Stace <s4...@yahoo.com> on 2002/02/07 14:45:23 UTC

Switching on UTF-8 Encoding

Hi

What do I need to do so that data returned from Tomcat 4 is returned in UTF-8 encoding to a requesting browser and
requests received are read as UTF-8.

-- 


Cheers

Tony。
---------------------------------------------------------------------


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Switching on UTF-8 Encoding

Posted by timothy <ti...@strategus.com.hk>.
i did it by using filter, it works quite good


>From Timothy

----- Original Message -----
From: "Antony Stace" <s4...@yahoo.com>
To: <to...@jakarta.apache.org>
Sent: Thursday, February 07, 2002 9:45 PM
Subject: Switching on UTF-8 Encoding


> Hi
>
> What do I need to do so that data returned from Tomcat 4 is returned in
UTF-8 encoding to a requesting browser and
> requests received are read as UTF-8.
>
> --
>
>
> Cheers
>
> Tony。
> ---------------------------------------------------------------------
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Switching on UTF-8 Encoding

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 7 Feb 2002, Antony Stace wrote:

> Date: Thu, 7 Feb 2002 22:45:23 +0900
> From: Antony Stace <s4...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Switching on UTF-8 Encoding
>
> Hi
>
> What do I need to do so that data returned from Tomcat 4 is returned in UTF-8 encoding to a requesting browser and
> requests received are read as UTF-8.
>

For writing UTF-8 content, your servlet needs to set the character
encoding *before* it gets the response's writer:

  response.setContentType("text/html;charset=UTF-8");
  PrintWriter writer = response.getWriter();
  writer.println("This line will be written in UTF-8");

For reading, the browser should have set a character encoding on its
"Content-Type" header.  If it didn't (or if this is a GET request and you
are trying to process query string parameters), call the following
*before* calling any of the request.getParameter methods (or
request.getReader):

  request.setCharacterEncoding("UTF-8");

Note that this method was added in Servlet 2.3, so it won't work in Tomcat
3.x environments.

> --
>
>
> Cheers
>
> Tony$B!#(B

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>