Quantcast

[S2] Chinese encoding problem

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[S2] Chinese encoding problem

Vincent Lin
Hi

I'm having problem to submit Chinese characters from browser to web server.

I have the following  settings in struts.properties:

struts.locale=zh_TW
struts.i18n.encoding=UT8

But when I submit Chinese characters to web server.
It gets scrambled characters.
(The wierd thing is that sometimes the server gets correct Chinese
characters.)

I've tried to use an interceptor to do req.setCharacterEncoding("UTF-8").
It doesn't work.

I've tried to use Servlet Filter to do req.setCharacterEncoding("UTF-8")
too.
(It's the way we solve Chinese problem in struts 1 environment).
It still doesn't work.

Does anyone know how to solve this problem?

Thanks a lot!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Vincent Lin
By the way the settings in my JSP:

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

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

Did I miss anything else?

On 6/27/07, Vincent Lin <[hidden email]> wrote:

>
> Hi
>
> I'm having problem to submit Chinese characters from browser to web
> server.
>
> I have the following  settings in struts.properties:
>
> struts.locale=zh_TW
> struts.i18n.encoding=UT8
>
> But when I submit Chinese characters to web server.
> It gets scrambled characters.
> (The wierd thing is that sometimes the server gets correct Chinese
> characters.)
>
> I've tried to use an interceptor to do req.setCharacterEncoding("UTF-8").
> It doesn't work.
>
> I've tried to use Servlet Filter to do req.setCharacterEncoding("UTF-8")
> too.
> (It's the way we solve Chinese problem in struts 1 environment).
> It still doesn't work.
>
> Does anyone know how to solve this problem?
>
> Thanks a lot!
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: [S2] Chinese encoding problem

Emilia Ipate
Vincent,
Your server must have as a Java VM Argument this line:
  -Dclient.encoding.override=UTF-8

(search on google client.encoding.override and you will find more)
Emilia





-----Original Message-----
From: Vincent Lin [mailto:[hidden email]]
Sent: Wednesday, June 27, 2007 12:56 PM
To: Struts Users Mailing List
Subject: Re: [S2] Chinese encoding problem

By the way the settings in my JSP:

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

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

Did I miss anything else?

On 6/27/07, Vincent Lin <[hidden email]> wrote:

>
> Hi
>
> I'm having problem to submit Chinese characters from browser to web
> server.
>
> I have the following  settings in struts.properties:
>
> struts.locale=zh_TW
> struts.i18n.encoding=UT8
>
> But when I submit Chinese characters to web server.
> It gets scrambled characters.
> (The wierd thing is that sometimes the server gets correct Chinese
> characters.)
>
> I've tried to use an interceptor to do
req.setCharacterEncoding("UTF-8").
> It doesn't work.
>
> I've tried to use Servlet Filter to do
req.setCharacterEncoding("UTF-8")
> too.
> (It's the way we solve Chinese problem in struts 1 environment).
> It still doesn't work.
>
> Does anyone know how to solve this problem?
>
> Thanks a lot!
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Vincent Lin
Emilia,

I've tried -Dclient.encoding.override=UTF-8, it doesn't seem to change
anything.

It's really wired that when I use IE, the Chinese characters will be
scramble.
But when I use firefox, it works correctly.

The funny thing is that the browser language setting of my IE is "zh_TW"
while the setting in firefox is "en".

Is there any interceptor in S2 changing the encoding of request?

On 6/27/07, Emilia Ipate <[hidden email]> wrote:

>
> Vincent,
> Your server must have as a Java VM Argument this line:
>   -Dclient.encoding.override=UTF-8
>
> (search on google client.encoding.override and you will find more)
> Emilia
>
>
>
>
>
> -----Original Message-----
> From: Vincent Lin [mailto:[hidden email]]
> Sent: Wednesday, June 27, 2007 12:56 PM
> To: Struts Users Mailing List
> Subject: Re: [S2] Chinese encoding problem
>
> By the way the settings in my JSP:
>
> <%@ page contentType="text/html; charset=UTF-8" %>
>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>
> Did I miss anything else?
>
> On 6/27/07, Vincent Lin <[hidden email]> wrote:
> >
> > Hi
> >
> > I'm having problem to submit Chinese characters from browser to web
> > server.
> >
> > I have the following  settings in struts.properties:
> >
> > struts.locale=zh_TW
> > struts.i18n.encoding=UT8
> >
> > But when I submit Chinese characters to web server.
> > It gets scrambled characters.
> > (The wierd thing is that sometimes the server gets correct Chinese
> > characters.)
> >
> > I've tried to use an interceptor to do
> req.setCharacterEncoding("UTF-8").
> > It doesn't work.
> >
> > I've tried to use Servlet Filter to do
> req.setCharacterEncoding("UTF-8")
> > too.
> > (It's the way we solve Chinese problem in struts 1 environment).
> > It still doesn't work.
> >
> > Does anyone know how to solve this problem?
> >
> > Thanks a lot!
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: [S2] Chinese encoding problem

Emilia Ipate
There is no interceptor, from what I know.

You should try to found where exactly lies the problem:
- is struts doing something wrong or the request got from the client is
already bad. You can check that by looking in the HttpRequest object, in
the debug mode


Emilia
-----Original Message-----
From: Vincent Lin [mailto:[hidden email]]
Sent: Wednesday, June 27, 2007 1:30 PM
To: Struts Users Mailing List
Subject: Re: [S2] Chinese encoding problem

Emilia,

I've tried -Dclient.encoding.override=UTF-8, it doesn't seem to change
anything.

It's really wired that when I use IE, the Chinese characters will be
scramble.
But when I use firefox, it works correctly.

The funny thing is that the browser language setting of my IE is "zh_TW"
while the setting in firefox is "en".

Is there any interceptor in S2 changing the encoding of request?

On 6/27/07, Emilia Ipate <[hidden email]> wrote:

>
> Vincent,
> Your server must have as a Java VM Argument this line:
>   -Dclient.encoding.override=UTF-8
>
> (search on google client.encoding.override and you will find more)
> Emilia
>
>
>
>
>
> -----Original Message-----
> From: Vincent Lin [mailto:[hidden email]]
> Sent: Wednesday, June 27, 2007 12:56 PM
> To: Struts Users Mailing List
> Subject: Re: [S2] Chinese encoding problem
>
> By the way the settings in my JSP:
>
> <%@ page contentType="text/html; charset=UTF-8" %>
>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>
> Did I miss anything else?
>
> On 6/27/07, Vincent Lin <[hidden email]> wrote:
> >
> > Hi
> >
> > I'm having problem to submit Chinese characters from browser to web
> > server.
> >
> > I have the following  settings in struts.properties:
> >
> > struts.locale=zh_TW
> > struts.i18n.encoding=UT8
> >
> > But when I submit Chinese characters to web server.
> > It gets scrambled characters.
> > (The wierd thing is that sometimes the server gets correct Chinese
> > characters.)
> >
> > I've tried to use an interceptor to do
> req.setCharacterEncoding("UTF-8").
> > It doesn't work.
> >
> > I've tried to use Servlet Filter to do
> req.setCharacterEncoding("UTF-8")
> > too.
> > (It's the way we solve Chinese problem in struts 1 environment).
> > It still doesn't work.
> >
> > Does anyone know how to solve this problem?
> >
> > Thanks a lot!
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Vincent Lin
But why does it works in Firefox while it doesn't work in IE?
I think it might be caused by different http request header made by IE and
Firefox.
There might be an Interceptor or servlet filter in struts2 which change the
character encoding according to the header of http request.


On 6/27/07, Emilia Ipate <[hidden email]> wrote:

>
> There is no interceptor, from what I know.
>
> You should try to found where exactly lies the problem:
> - is struts doing something wrong or the request got from the client is
> already bad. You can check that by looking in the HttpRequest object, in
> the debug mode
>
>
> Emilia
> -----Original Message-----
> From: Vincent Lin [mailto:[hidden email]]
> Sent: Wednesday, June 27, 2007 1:30 PM
> To: Struts Users Mailing List
> Subject: Re: [S2] Chinese encoding problem
>
> Emilia,
>
> I've tried -Dclient.encoding.override=UTF-8, it doesn't seem to change
> anything.
>
> It's really wired that when I use IE, the Chinese characters will be
> scramble.
> But when I use firefox, it works correctly.
>
> The funny thing is that the browser language setting of my IE is "zh_TW"
> while the setting in firefox is "en".
>
> Is there any interceptor in S2 changing the encoding of request?
>
> On 6/27/07, Emilia Ipate <[hidden email]> wrote:
> >
> > Vincent,
> > Your server must have as a Java VM Argument this line:
> >   -Dclient.encoding.override=UTF-8
> >
> > (search on google client.encoding.override and you will find more)
> > Emilia
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: Vincent Lin [mailto:[hidden email]]
> > Sent: Wednesday, June 27, 2007 12:56 PM
> > To: Struts Users Mailing List
> > Subject: Re: [S2] Chinese encoding problem
> >
> > By the way the settings in my JSP:
> >
> > <%@ page contentType="text/html; charset=UTF-8" %>
> >
> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> >
> > Did I miss anything else?
> >
> > On 6/27/07, Vincent Lin <[hidden email]> wrote:
> > >
> > > Hi
> > >
> > > I'm having problem to submit Chinese characters from browser to web
> > > server.
> > >
> > > I have the following  settings in struts.properties:
> > >
> > > struts.locale=zh_TW
> > > struts.i18n.encoding=UT8
> > >
> > > But when I submit Chinese characters to web server.
> > > It gets scrambled characters.
> > > (The wierd thing is that sometimes the server gets correct Chinese
> > > characters.)
> > >
> > > I've tried to use an interceptor to do
> > req.setCharacterEncoding("UTF-8").
> > > It doesn't work.
> > >
> > > I've tried to use Servlet Filter to do
> > req.setCharacterEncoding("UTF-8")
> > > too.
> > > (It's the way we solve Chinese problem in struts 1 environment).
> > > It still doesn't work.
> > >
> > > Does anyone know how to solve this problem?
> > >
> > > Thanks a lot!
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Christopher Schultz-2
In reply to this post by Vincent Lin
Vincent,

Vincent Lin wrote:
> I'm having problem to submit Chinese characters from browser to web server.

GET, POST, or both?

If it's only failing for GET, check to make sure that your app server
knows to expect UTF-8 strings in URLs (in Tomcat, for instance, this is
specified in the <Connector> element of your configuration).

-chris



signature.asc (258 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Vincent Lin
I use POST in my form.

On 6/27/07, Christopher Schultz <[hidden email]> wrote:

>
> Vincent,
>
> Vincent Lin wrote:
> > I'm having problem to submit Chinese characters from browser to web
> server.
>
> GET, POST, or both?
>
> If it's only failing for GET, check to make sure that your app server
> knows to expect UTF-8 strings in URLs (in Tomcat, for instance, this is
> specified in the <Connector> element of your configuration).
>
> -chris
>
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Christopher Schultz-2
Vincent,

Vincent Lin wrote:
> I use POST in my form.

:(

You mentioned that MSIE seems to fail, while Mozilla Firefox works. Is
this behavior consistent? Does ff always work? Does MSIE always fail?

Can you check to see what character encoding (in the HTTP headers) is
being sent from the client when things work? What about the failure
situation?

It's possible that MSIE is not sending the correct request encoding (or,
more likely,not sending it at all). If you know your clients will (or
should) be sending UTF-8 all the time, you could use the
CharacterEncodingFilter mentioned on this list several times to simply
override the default encoding used when the browser sends no encoding
(or override it unconditionally). This might work.

-chris



signature.asc (258 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Vincent Lin
Chris,

Thank you.
I solved this problem finally.

I use a CharacterEncodingFilter you mentioned to set character encoding to
UTF-8.
Actually I've tried this filter before, but it didn't work.
The reason why it didn't work is the order of fitler mapping is incorrect in
my web.xml.
This filter must be in front of struts 2 filter like this:

    <filter-mapping>
        <filter-name>SetCharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

But it sitll strange that I've traced the struts 2.0.6 source code and found
that id does change the encoding of HttpServletRequest in
Dispatcher.java(line 650):

    public void prepare(HttpServletRequest request, HttpServletResponse
response) {
        String encoding = null;
        if (defaultEncoding != null) {
            encoding = defaultEncoding;
        }

        Locale locale = null;
        if (defaultLocale != null) {
            locale = LocalizedTextUtil.localeFromString(defaultLocale,
request.getLocale());
        }

        if (encoding != null) {
            try {
                request.setCharacterEncoding(encoding);
            } catch (Exception e) {
                LOG.error("Error setting character encoding to '" + encoding
+ "' - ignoring.", e);
            }
        }

        if (locale != null) {
            response.setLocale(locale);
        }

        if (paramsWorkaroundEnabled) {
            request.getParameter("foo"); // simply read any parameter
(existing or not) to "prime" the request
        }
    }

And there is a setDefaultEncoding() method in line 227:
@Inject(value=StrutsConstants.STRUTS_LOCALE, required=false)
    public static void setDefaultLocale(String val) {
        defaultLocale = val;
    }

It seems to get encoding parameter from struts.propertes with key
struts.i18n.encoding in struts.properties file.
But somehow it doesn't work in my app.

The filter has solved this problem. But I think in struts 2, we shouldn't do
this filter?
It makes the code a bit ugly.

The behaviors in IE and Firefox are different really confuses me.
Why the browser affect the character encoding in HttpServletRequest?

On 6/27/07, Christopher Schultz <[hidden email]> wrote:

>
> Vincent,
>
> Vincent Lin wrote:
> > I use POST in my form.
>
> :(
>
> You mentioned that MSIE seems to fail, while Mozilla Firefox works. Is
> this behavior consistent? Does ff always work? Does MSIE always fail?
>
> Can you check to see what character encoding (in the HTTP headers) is
> being sent from the client when things work? What about the failure
> situation?
>
> It's possible that MSIE is not sending the correct request encoding (or,
> more likely,not sending it at all). If you know your clients will (or
> should) be sending UTF-8 all the time, you could use the
> CharacterEncodingFilter mentioned on this list several times to simply
> override the default encoding used when the browser sends no encoding
> (or override it unconditionally). This might work.
>
> -chris
>
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [S2] Chinese encoding problem

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent,

Vincent Lin wrote:
> I solved this problem finally.

That's good, but ....

> But it still strange that I've traced the struts 2.0.6 source code
> and found that id does change the encoding of HttpServletRequest in
> Dispatcher.java(line 650):

[snip]

>        if (encoding != null) {
>            try {
>                request.setCharacterEncoding(encoding);
>            } catch (Exception e) {
>                LOG.error("Error setting character encoding to '" + encoding
> + "' - ignoring.", e);
>            }
>        }

[snip]

> It seems to get encoding parameter from struts.properties with key
> struts.i18n.encoding in struts.properties file.
> But somehow it doesn't work in my app.

So, setting "struts.i18n.encoding=UTF8" in struts.properties doesn't
work? Do you know how the "Inject" annotation works? I certainly don't.
Are you sure that's not a system property (instead of a property loaded
from a file)?

> The filter has solved this problem. But I think in struts 2, we
> shouldn't [use] this filter? It makes the code a bit ugly.

I agree. It seems like S2 includes the capability of fixing the request
encoding (and should do the same thing as the CharacterEncodingFilter).
Perhaps it's just not configured properly.

> The behaviors in IE and Firefox are different really confuses me.
> Why the browser affect the character encoding in HttpServletRequest?

I would bet that Firefox is better about reporting the encoding of the
request, and it's sending "UTF8" as part of the encoding header. MSIE
might just be assuming that since the server sent the (previous)
response as UTF-8, that the server will expect UTF-8 in the (next)
request, so it doesn't bother to mention it. That's just a wild guess.

The inconsistency of browsers and servers with regard to character
encoding of requests and URLs is shocking. :(

- -chris

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

iD8DBQFGg85T9CaO5/Lv0PARAt4pAJ9rzppybyanmGVDsakmbI58auqt5QCeONJN
+PLvOL7Gig4SNF1yhhzCl54=
=Iq05
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Setting an interceptor across all actions

Session Mwamufiya
In reply to this post by Christopher Schultz-2
Hi,

I've been doing some readin on interceptors, and am wondering whether there's a way to declare a login type of interceptor only once and have it apply across my entire app.  I'm looking for something other than having every package extend the one in which the interceptor is defined.

Thanks,
Session


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Changing the "target" html window for an interceptor's result

Session Mwamufiya
In reply to this post by Christopher Schultz-2
Hi,

I'm using frames in my app; my login page is not within a frame, but it goes to a page with frames once a user is authenticated.  I have 2 frames: a control frame on the left and a display frame on the right.  Going from my login to the main page (with frames) is not an issue, but I'm also using an interceptor to handle my login, so if the session object expires, then the interceptor brings back the login page.  The problem with that is that once my session object expires and a login is required, my login page appears in the display window frame, and not in a no-frame page like before.  I'm wondering whether there is a way to specify something like a frame "target" element to make sure that the resulting page is displayed the way I'd want it to be.

Thanks,
Session


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Setting an interceptor across all actions

newton.dave
In reply to this post by Session Mwamufiya
--- Session A Mwamufiya wrote:
> I've been doing some readin on interceptors, and am
> wondering whether there's a way to declare a login
> type of interceptor only once and have it apply
> across my entire app.  I'm looking for something
> other than having every package extend the one in
> which the interceptor is defined.

AFAIK packages are hierarchical; if you don't define
it in a higher-level package I don't see how it would
be visible to lower-level packages. (Unless you change
the default package, obviously.)

d.



 
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Setting an interceptor across all actions

Session Mwamufiya
Thanks, that answers my question.

Session


> --- Session A Mwamufiya wrote:
>> I've been doing some readin on interceptors, and am wondering whether
>> there's a way to declare a login type of interceptor only once and have
>> it apply across my entire app.  I'm looking for something other than
>> having every package extend the one in which the interceptor is defined.
>>
>
> AFAIK packages are hierarchical; if you don't define it in a higher-level
> package I don't see how it would be visible to lower-level packages.
> (Unless you change the default package, obviously.)
>
> d.
>
>
>
>
> _________________________________________________________________________
> ___________ We won't tell. Get more on shows you hate to love (and love to
> hate): Yahoo! TV's Guilty Pleasures list.
> http://tv.yahoo.com/collections/265
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: [hidden email] For additional
> commands, e-mail: [hidden email]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...