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 <[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