|
|
How to handle UTF-8 characters in struts ApplicationResources.properties
I used WSAD5 and struts to develop a Japaness site using UTF-8. I
defined error message in strut's ApplicationResources.properties file.
If the error message contains Japaness characters (UTF-8 encoding), it
will not be displayed correctly in the browser.
For example ApplicationResources.properties contains the following:
error.login.invalidCredential=3D=E5=90=89=E5=B7=9D=E8=8B=B1=E4=B8=80=E9=83=
=8E: Your userName/password
is invalid. Please try again.
I raise this error in my action class as follow:
errors.add("login", new ActionError("error.login.invalidCredential"));
In the JSP I displayed the error using
<html:errors />
When I run the application, the JSP display the following message:
=C3=A5=C2=90=C2=89=C3=A5=C2=B7=C2=9D=C3=A8=C2=8B=C2=B1=C3=A4=C2=B8=C2=80=C3=
=A9=C2=83=C2=8E: Your userName/password is invalid.
Please try again.
Note that the English characters are displayed correctly but not the
Japaness characters.
What is wrong?
Ningjun
|
|
0
|
|
|
|
Reply
|
ningjun.wang (11)
|
1/10/2005 7:14:01 PM |
|
ningjun.wang@lexisnexis.com wrote:
> I used WSAD5 and struts to develop a Japaness site using UTF-8. I
> defined error message in strut's ApplicationResources.properties file.
> If the error message contains Japaness characters (UTF-8 encoding), it
> will not be displayed correctly in the browser.
>
> For example ApplicationResources.properties contains the following:
>
> error.login.invalidCredential=吉川英一郎: Your userName/password
> is invalid. Please try again.
>
> I raise this error in my action class as follow:
>
> errors.add("login", new ActionError("error.login.invalidCredential"));
>
> In the JSP I displayed the error using
> <html:errors />
>
> When I run the application, the JSP display the following message:
>
> åå·è±ä¸é: Your userName/password is invalid.
> Please try again.
>
>
> Note that the English characters are displayed correctly but not the
> Japaness characters.
>
> What is wrong?
It certainly looks like a character encoding mismatch. The default
character encoding for HTTP is ISO-8859-1 (and this is also explicitly
specified by JSP as the default encoding for responses). I observe that
all the incorrect characters you provided do appear to be among those
provided by ISO-8859-1. To indicate the correct charset in straight JSP
you would specifically set the character encoding for the response (and
the default encoding for the JSP text) by means of the contentType
attribute of a <@page> directive. For example:
<@page contentType="text/html; charset=UTF-8">
In a servlet you would invoke the response object's setContentType()
method. Struts may have a convenient way to handle this for you; I
don't know Struts well enough to tell you one way or another.
John Bollinger
jobollin@indiana.edu
|
|
0
|
|
|
|
Reply
|
jobollin (1553)
|
1/10/2005 8:23:50 PM
|
|
ningjun.wang@lexisnexis.com wrote:
> I used WSAD5 and struts to develop a Japaness site using UTF-8. I
> defined error message in strut's ApplicationResources.properties file.
> If the error message contains Japaness characters (UTF-8 encoding), it
> will not be displayed correctly in the browser.
>
> For example ApplicationResources.properties contains the following:
>
> error.login.invalidCredential=?????: Your userName/password
> is invalid. Please try again.
Please note that a .properties file use the ISO 8859-1 character encoding,
so using UTF-8 characters in those files is not supported. See the
javadocs for java.util.RecourceBundle, java.util.PropertyResourceBundle
and java.util.Properties; especially this part:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding
BTW, struts uses java.util.Properies directly.
--
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
|
|
0
|
|
|
|
Reply
|
oscar1 (318)
|
1/11/2005 6:37:32 PM
|
|
I already set JSP contentType to UTF-8 using
res.setContentType("text/html; charset=UTF-8");
in the servlet as well as
<@page contentType="text/html; charset=UTF-8">
in the JSP. It does not work.
By the way, I have many Japaness characters displayed on the same JSP
correctly. Only those error messages presented by <html:errors /> do
not display correctly. Therefore I believe the problem is how struts
read the message property file. What encoding does struts use to read
message property files?
Ningjun
|
|
0
|
|
|
|
Reply
|
ningjun.wang (11)
|
1/11/2005 6:48:29 PM
|
|
On 10 Jan 2005 11:14:01 -0800, ningjun.wang@lexisnexis.com wrote:
> I used WSAD5 and struts to develop a Japaness site ..
URL?
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
|
0
|
|
|
|
Reply
|
SeeMySites (3836)
|
1/12/2005 8:00:55 AM
|
|
ningjun.wang@lexisnexis.com wrote:
> I used WSAD5 and struts to develop a Japaness site using UTF-8. I
> defined error message in strut's ApplicationResources.properties file.
> If the error message contains Japaness characters (UTF-8 encoding), it
> will not be displayed correctly in the browser.
>
> For example ApplicationResources.properties contains the following:
>
> error.login.invalidCredential=吉川英一郎: Your userName/password
> is invalid. Please try again.
>
> I raise this error in my action class as follow:
>
> errors.add("login", new ActionError("error.login.invalidCredential"));
>
> In the JSP I displayed the error using
> <html:errors />
>
> When I run the application, the JSP display the following message:
>
> åå·è±ä¸é: Your userName/password is invalid.
> Please try again.
>
>
> Note that the English characters are displayed correctly but not the
> Japaness characters.
>
> What is wrong?
>
> Ningjun
>
Have you tried using
error.login.invalidCredential=\u5409\u5DDD\u82F1\u4E00\u4E00
(Note the codepoints may be wrong, I didn't check)
|
|
0
|
|
|
|
Reply
|
lg83news (33)
|
1/12/2005 3:43:26 PM
|
|
> Have you tried using
> error.login.invalidCredential=3D\u5409\u5DDD\u82F1\u4E00\u4E00
Yes, it works. I hope I can put real Japaness characters such as =E5=90=89=
=E5=B7=9D
there. But I can live with using \u.
Thanks for the help.
|
|
0
|
|
|
|
Reply
|
ningjun.wang (11)
|
1/13/2005 2:52:14 PM
|
|
|
6 Replies
18 Views
(page loaded in 0.127 seconds)
|
|
|
|
|
|
|
|
|