You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2007/05/08 17:25:36 UTC

Struts2 character code question

I have set my all files with UTF-8 format,so I set URIEncoding parameter in
server.xml in tomcat6.0.10,like follows:
<Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>
Then I write a JSP file like follows:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:form method="post" action="test.do">
<s:textfield label="Name" name="Name"/>
<s:submit name="do"/>
</s:form>

In test.do action,I get the value of Name from JSP,like follows:
request.getParameter("Name");
System.out.println("Name="+Name);
If I input english name in the field Name in JSP,when I submit,the
test.dowill receive right english name,but when I input chinese name
in the field
Name in JSP,test.do will receive not right name,it will show ???[B@15b1773
I know it must be wrong in character change.But I don't want to change
URIEncoding from UTF-8 to GB2312 in the server.xml file,I guess I should do
something in test.do,but I don't know how to do it.
Anybody could tell me how to do it? Would you give me some code?

Thanks

Re: Struts2 character code question

Posted by red phoenix <ro...@gmail.com>.
I have set URIEncoding="UTF-8"
and when I submit as
 <s:form method="post" action=" test.do?Name=Chinese code">

and I get String name=request.getParameter("Name")
it get name as UTF-8 format,so I can't get right chinese code

I tried set <Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443" URIEncoding="GB2312"/>

This time,I can get right chinese code in test.do by
String name=request.getParameter("Name")

But i only want to set <Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>

Anybody could tell me how to do in test.do file?



On 5/9/07, Martin Gainty <mg...@hotmail.com> wrote:
>
> apparently ISO2022_CN_GB is Mandarin
> (http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html)
> since this is most decidedly DBCS did you load CJK IME /Keyboard and
> Fonts?
>
> M--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
> ----- Original Message -----
> From: "red phoenix" <ro...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, May 08, 2007 8:47 PM
> Subject: Re: Struts2 character code question
>
>
> >I tried follows in test.do:
> > String name=request.getParameter("Name");
> > System.out.println(new String(name.getBytes("UTF-8"), "gb2312"))
> > it still show ???[B@15b1773,Why?
> >
> >
> >
> > On 5/8/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
> >>
> >> -----BEGIN PGP SIGNED MESSAGE-----
> >> Hash: SHA1
> >>
> >> Red,
> >>
> >> red phoenix wrote:
> >> > If I input English name in the field Name in JSP,when I submit,the
> >> > test.do will receive right English name,but when I input Chinese name
> >> > in the field Name in JSP, test.do will receive not right name,it will
> >> > show ???[B@15b1773
> >>
> >> This is what you get when you print out a byte array. Try converting
> the
> >> byte array to a String using "new String(bytes, charset)" and printing
> >> that.
> >>
> >> - -chris
> >> -----BEGIN PGP SIGNATURE-----
> >> Version: GnuPG v1.4.7 (MingW32)
> >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >>
> >> iD8DBQFGQJwZ9CaO5/Lv0PARAmyvAJ9aCJZ/MINdBzS18ytQMgzf4M8D3ACffHSG
> >> Ldprq3v5ZTLxYF80HoafTOY=
> >> =vx7I
> >> -----END PGP SIGNATURE-----
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 character code question

Posted by Martin Gainty <mg...@hotmail.com>.
apparently ISO2022_CN_GB is Mandarin 
(http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html)
since this is most decidedly DBCS did you load CJK IME /Keyboard and Fonts?

M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "red phoenix" <ro...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, May 08, 2007 8:47 PM
Subject: Re: Struts2 character code question


>I tried follows in test.do:
> String name=request.getParameter("Name");
> System.out.println(new String(name.getBytes("UTF-8"), "gb2312"))
> it still show ???[B@15b1773,Why?
>
>
>
> On 5/8/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
>>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Red,
>>
>> red phoenix wrote:
>> > If I input English name in the field Name in JSP,when I submit,the
>> > test.do will receive right English name,but when I input Chinese name
>> > in the field Name in JSP, test.do will receive not right name,it will
>> > show ???[B@15b1773
>>
>> This is what you get when you print out a byte array. Try converting the
>> byte array to a String using "new String(bytes, charset)" and printing
>> that.
>>
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.7 (MingW32)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>> iD8DBQFGQJwZ9CaO5/Lv0PARAmyvAJ9aCJZ/MINdBzS18ytQMgzf4M8D3ACffHSG
>> Ldprq3v5ZTLxYF80HoafTOY=
>> =vx7I
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 


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


Re: Struts2 character code question

Posted by red phoenix <ro...@gmail.com>.
I tried follows in test.do:
String name=request.getParameter("Name");
System.out.println(new String(name.getBytes("UTF-8"), "gb2312"))
it still show ???[B@15b1773,Why?



On 5/8/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Red,
>
> red phoenix wrote:
> > If I input English name in the field Name in JSP,when I submit,the
> > test.do will receive right English name,but when I input Chinese name
> > in the field Name in JSP, test.do will receive not right name,it will
> > show ???[B@15b1773
>
> This is what you get when you print out a byte array. Try converting the
> byte array to a String using "new String(bytes, charset)" and printing
> that.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGQJwZ9CaO5/Lv0PARAmyvAJ9aCJZ/MINdBzS18ytQMgzf4M8D3ACffHSG
> Ldprq3v5ZTLxYF80HoafTOY=
> =vx7I
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 character code question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Red,

red phoenix wrote:
> If I input English name in the field Name in JSP,when I submit,the 
> test.do will receive right English name,but when I input Chinese name 
> in the field Name in JSP, test.do will receive not right name,it will
> show ???[B@15b1773

This is what you get when you print out a byte array. Try converting the
byte array to a String using "new String(bytes, charset)" and printing that.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQJwZ9CaO5/Lv0PARAmyvAJ9aCJZ/MINdBzS18ytQMgzf4M8D3ACffHSG
Ldprq3v5ZTLxYF80HoafTOY=
=vx7I
-----END PGP SIGNATURE-----

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