Hi there, I'm encounting a request encoding problem using struts 2. Users may be send urls mainly in two encodins: UTF-8 or GBK. For Firefox, it will encode urls to UTF-8 before sending them to server, by default. For IE, it will leave urls as it is by default.
Anyway, the urls received by server may not be encoded in UTF-8 format. When this happened, by detecting (charcode > 127) in querystring of request, I'll manually set request's contentEncoding property to "GBK". But Dispatcher simply ignored my effort and reset contentEncoding to "UTF-8", which is my default contentEncoding of my webapp. Below is the source code of org.apache.struts2.dispatcher.Dispatcher.java (from svn): ================line 587 to 604============== 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); } } ============================================= I think these lines should be modified as: ============================================= public void prepare(HttpServletRequest request, HttpServletResponse response) { String encoding = request.getCharacterEncoding(); if (encoding == null && defaultEncoding != null) { try { request.setCharacterEncoding(defaultEncoding); } catch (Exception e) { LOG.error("Error setting character encoding to '" + defaultEncoding+ "' - ignoring.", e); } } Locale locale = null; if (defaultLocale != null) { locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale()); } ============================================= I've patched Dispatcher.java in my webapp and worked well. Also, locale should be retreived from request by request.getLocale() first, and then set it to defaultLocale when none locale exists in current request. Any suggestions? Should I fire a bug? -Wesley