You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by vi...@mac.com on 2003/05/22 00:09:20 UTC

Struts example does not work with unicode

Hi All,

In the Struts example (MailReader Demonstration) when I try to enter
japanese user name in the login page 
I get a validation error, but, the orignal text comes back all garbled
up. Anyone know how to fix this?

The logon.jsp page has this also

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

I am using Tomcat 4.1.24 running on Windows 2000 and J2SE 1.4.1

Thanks in advance.

- vineet


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts example does not work with unicode

Posted by Vineet Bhatia <vi...@mac.com>.
Aha!! Thanks!!

Someone should patch this on the struts-example.

- vineet

On 5/21/03 7:46 PM, "Jason Lea" <ja...@kumachan.net.nz> wrote:

> vineetb@mac.com wrote:
>> Hi All,
>> 
>> In the Struts example (MailReader Demonstration) when I try to enter
>> japanese user name in the login page
>> I get a validation error, but, the orignal text comes back all garbled
>> up. Anyone know how to fix this?
>> 
>> The logon.jsp page has this also
>> 
>> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
>> 
>> I am using Tomcat 4.1.24 running on Windows 2000 and J2SE 1.4.1
>> 
>> Thanks in advance.
> 
> I think the problem is the character encoding on the information posted
> to the server.  The server will be defaulting to Latin1 encoding when
> reading the parameters which means the 3 bytes per character you are
> sending is interpreted as 3 separate characters.
> 
> You need to do a request.setCharacterEncoding("UTF-8") before anything
> is read from the request parameters.  Then the server will be able to
> correctly read the 3 bytes as a single character.
> 
> I use a filter that sets the encoding for all pages:
> 
> public void doFilter(ServletRequest req, ServletResponse res,
> FilterChain chain) throws IOException, ServletException {
>    HttpServletRequest request = (HttpServletRequest)req;
>    request.setCharacterEncoding("UTF-8");
>    chain.doFilter(req, res);
> }
> 
> You could put the code somewhere else, but I don't think you can put it
> in an Action because an Action is called after the ActionForm has been
> populated with the request parameters.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts example does not work with unicode

Posted by Jason Lea <ja...@kumachan.net.nz>.
vineetb@mac.com wrote:
> Hi All,
> 
> In the Struts example (MailReader Demonstration) when I try to enter
> japanese user name in the login page 
> I get a validation error, but, the orignal text comes back all garbled
> up. Anyone know how to fix this?
> 
> The logon.jsp page has this also
> 
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> 
> I am using Tomcat 4.1.24 running on Windows 2000 and J2SE 1.4.1
> 
> Thanks in advance.

I think the problem is the character encoding on the information posted 
to the server.  The server will be defaulting to Latin1 encoding when 
reading the parameters which means the 3 bytes per character you are 
sending is interpreted as 3 separate characters.

You need to do a request.setCharacterEncoding("UTF-8") before anything 
is read from the request parameters.  Then the server will be able to 
correctly read the 3 bytes as a single character.

I use a filter that sets the encoding for all pages:

public void doFilter(ServletRequest req, ServletResponse res, 
FilterChain chain) throws IOException, ServletException {
     HttpServletRequest request = (HttpServletRequest)req;
     request.setCharacterEncoding("UTF-8");
     chain.doFilter(req, res);
}

You could put the code somewhere else, but I don't think you can put it 
in an Action because an Action is called after the ActionForm has been 
populated with the request parameters.

-- 
Jason Lea


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org