You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antony Stace <s4...@yahoo.com> on 2002/02/07 10:24:42 UTC

Problem with UTF encoding with Action Form

Hi

I have a jsp page in UTF-8 format with a form in it a user fills out, this form is a session scope Action Form.
The user then submits the request and the
same page gets returned with the form values from the previous submit on this screen.  I did not change the
values anyway of the Action Form, they should be the same ones the user submitted in their first step.  However, all the fields 
in this populated form are all garbage.  
Any idea where my problem is?

-- 


Cheers

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


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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with UTF encoding with Action Form

Posted by Michael Baldwin <mi...@sun.com>.
Try reading a really good resource on character set encoding.
http://tagunov.newmail.ru/i18n/i18n.html

It sounds to me like the request params aren't being decoded properly when they are being
processed by the web container.

I'd suggest looking at the section on "Decoding request parameters under Servlet 2.3
containers".
The 2.3 method on the request, "request.setCharacterEncoding( String env )".  It might be
just what you're looking for.  As long as you call this method before any of there request
params are read (which means you'll have to mod the controller servlet), you can specify
whatever encoding you want when reading the chars from the request.

You could get fancier with supporting multiple character sets in your app by checking the
user's locale and making some assumptions about what character sets are used (GB for
Chinese, Big5 for others, etc.)

--Michael

Antony Stace wrote:

> Thanks Chris for the reply.
>
> > I've just looked in the JSP spec. and you're quite right, the "@page content
> > ..." directive sets the encoding used by the Writer.  You also correctly
> > stated that you need:
> >
> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> >
> > as well.
> >
> > Hopefully that should do the trick.
>
> Umm.....I have this and I get the garbage characters....Where to go from here I wonder.
>
> --
>
> Cheers
>
> Tony$B!#(B
> ---------------------------------------------------------------------
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Problem with UTF encoding with Action Form

Posted by Chris Birch <ch...@artlas.net>.
Tony,

Try sending your request to your server via a telnet connection.  That way
you will be able to see in the headers if the correct content type has been
set and what the character values are that are returned.  I'd suggest
creating a file with the HTTP POST in and having telnet read it.  Bit of a
pain but then at least you'd know what was happening.  Actually, rather than
messing with multi-part posts, you could probably use a HTTP GET with the
name/value pairs tagged onto the URL.

What servlet container are you using?  There is a possibility of a bug with
the page directive...

Regards,
Chris.

-----Original Message-----
From: Antony Stace [mailto:s45652001@yahoo.com]
Sent: 07 February 2002 13:47
To: Struts Users Mailing List
Subject: Re: Problem with UTF encoding with Action Form


Thanks Chris for the reply.

> I've just looked in the JSP spec. and you're quite right, the "@page
content
> ..." directive sets the encoding used by the Writer.  You also correctly
> stated that you need:
>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>
> as well.
>
> Hopefully that should do the trick.

Umm.....I have this and I get the garbage characters....Where to go from
here I wonder.


--


Cheers

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


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


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with UTF encoding with Action Form

Posted by Antony Stace <s4...@yahoo.com>.
Thanks Chris for the reply.

> I've just looked in the JSP spec. and you're quite right, the "@page content
> ..." directive sets the encoding used by the Writer.  You also correctly
> stated that you need:
> 
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> 
> as well.
> 
> Hopefully that should do the trick.

Umm.....I have this and I get the garbage characters....Where to go from here I wonder.


-- 


Cheers

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


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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Problem with UTF encoding with Action Form

Posted by Chris Birch <ch...@artlas.net>.
Hi,

I've just looked in the JSP spec. and you're quite right, the "@page content
..." directive sets the encoding used by the Writer.  You also correctly
stated that you need:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

as well.

Hopefully that should do the trick.

Regards,
Chris.

-----Original Message-----
From: Antony Stace [mailto:s45652001@yahoo.com]
Sent: 07 February 2002 13:11
To: Struts Users Mailing List
Subject: Re: Problem with UTF encoding with Action Form


Hi Chris

Thanks for the reply.

On Thu, 7 Feb 2002 12:32:27 -0000
"Chris Birch" <ch...@artlas.net> wrote:

> Hi,
>
> The following is taken from javax.servlet.ServletResponse:
>
> ---
> The charset for the MIME body response can be specified with
> setContentType(java.lang.String). For example, "text/html;
> charset=Shift_JIS". The charset can alternately be set using
> setLocale(java.util.Locale). If no charset is specified, ISO-8859-1 will
be
> used. The setContentType or setLocale method must be called before
getWriter
> for the charset to affect the construction of the writer.
> ---
>
> If your UTF-8 chars are inside the normal ascii range then you shouldn't
> have a problem, for those outside, its using the wrong encoding.

They are outside - Japanese Characters.

> You will
> need to set the appropiate content type in response object.

Isn't this done by

<%@ page contentType="text/html; charset=UTF-8" %>

or do I need to do this in the Action.perform() method by

response.setContentType("text/html;charset=UTF-8;");

?

>Also, you must
> specify the charset in your HTML (in jsp) as well, otherwise the browser
> wont know which charset to use to display the characters.

do you mean

<%@ page contentType="text/html; charset=UTF-8" %>
or

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

>
> I saw a post on here a while ago that said IE often ignores the charset
> specified and it had to be changed manually.

I shall watch out for this.

Thanks for the help


--


Cheers

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


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


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with UTF encoding with Action Form

Posted by Antony Stace <s4...@yahoo.com>.
Hi Chris 

Thanks for the reply.

On Thu, 7 Feb 2002 12:32:27 -0000
"Chris Birch" <ch...@artlas.net> wrote:

> Hi,
> 
> The following is taken from javax.servlet.ServletResponse:
> 
> ---
> The charset for the MIME body response can be specified with
> setContentType(java.lang.String). For example, "text/html;
> charset=Shift_JIS". The charset can alternately be set using
> setLocale(java.util.Locale). If no charset is specified, ISO-8859-1 will be
> used. The setContentType or setLocale method must be called before getWriter
> for the charset to affect the construction of the writer.
> ---
> 
> If your UTF-8 chars are inside the normal ascii range then you shouldn't
> have a problem, for those outside, its using the wrong encoding. 

They are outside - Japanese Characters.

> You will
> need to set the appropiate content type in response object.  

Isn't this done by

<%@ page contentType="text/html; charset=UTF-8" %>

or do I need to do this in the Action.perform() method by

response.setContentType("text/html;charset=UTF-8;");

?

>Also, you must
> specify the charset in your HTML (in jsp) as well, otherwise the browser
> wont know which charset to use to display the characters.

do you mean

<%@ page contentType="text/html; charset=UTF-8" %>
or

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

> 
> I saw a post on here a while ago that said IE often ignores the charset
> specified and it had to be changed manually.

I shall watch out for this.

Thanks for the help


-- 


Cheers

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


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


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Problem with UTF encoding with Action Form

Posted by Chris Birch <ch...@artlas.net>.
Hi,

The following is taken from javax.servlet.ServletResponse:

---
The charset for the MIME body response can be specified with
setContentType(java.lang.String). For example, "text/html;
charset=Shift_JIS". The charset can alternately be set using
setLocale(java.util.Locale). If no charset is specified, ISO-8859-1 will be
used. The setContentType or setLocale method must be called before getWriter
for the charset to affect the construction of the writer.
---

If your UTF-8 chars are inside the normal ascii range then you shouldn't
have a problem, for those outside, its using the wrong encoding.  You will
need to set the appropiate content type in response object.  Also, you must
specify the charset in your HTML (in jsp) as well, otherwise the browser
wont know which charset to use to display the characters.

I saw a post on here a while ago that said IE often ignores the charset
specified and it had to be changed manually.

Hope this helps,
Chris.



-----Original Message-----
From: Antony Stace [mailto:s45652001@yahoo.com]
Sent: 07 February 2002 09:25
To: struts-user@jakarta.apache.org
Subject: Problem with UTF encoding with Action Form


Hi

I have a jsp page in UTF-8 format with a form in it a user fills out, this
form is a session scope Action Form.
The user then submits the request and the
same page gets returned with the form values from the previous submit on
this screen.  I did not change the
values anyway of the Action Form, they should be the same ones the user
submitted in their first step.  However, all the fields
in this populated form are all garbage.
Any idea where my problem is?

--


Cheers

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


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


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>