Re: [S2] Chinese encoding problem
-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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] Chinese encoding problem
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: SetCharacterEncoding /* struts2 /* 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 <[EMAIL PROTECTED]> 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
Re: [S2] Chinese encoding problem
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 Description: OpenPGP digital signature
Re: [S2] Chinese encoding problem
I use POST in my form. On 6/27/07, Christopher Schultz <[EMAIL PROTECTED]> 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 element of your configuration). -chris
Re: [S2] Chinese encoding problem
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 element of your configuration). -chris signature.asc Description: OpenPGP digital signature
Re: [S2] Chinese encoding problem
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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] 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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] > 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" %> > > > > Did I miss anything else? > > On 6/27/07, Vincent Lin <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [S2] Chinese encoding problem
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:[EMAIL PROTECTED] 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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] > 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" %> > > > > Did I miss anything else? > > On 6/27/07, Vincent Lin <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] 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" %> Did I miss anything else? On 6/27/07, Vincent Lin <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [S2] Chinese encoding problem
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:[EMAIL PROTECTED] 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" %> Did I miss anything else? On 6/27/07, Vincent Lin <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] Chinese encoding problem
By the way the settings in my JSP: <%@ page contentType="text/html; charset=UTF-8" %> Did I miss anything else? On 6/27/07, Vincent Lin <[EMAIL PROTECTED]> 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!
[S2] Chinese encoding problem
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!