使用jakarta commons-upload。
升級到2.2.2后發(fā)現(xiàn)上傳中文會亂碼。
經(jīng)過跟蹤發(fā)現(xiàn)在com.opensymphony.webwork.dispatcher.DispatcherUtils的prepare(HttpServletRequest request, HttpServletResponse response)方法。
2.2.1->2.2.2時這個方法發(fā)生了非常的的變化。
2.2.1時:?
public?void?prepare(HttpServletRequest?request,?HttpServletResponse?response)?{?
????????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?
????????}?
????}
2.2.2時:
public?void?prepare(HttpServletRequest?request,?HttpServletResponse?response)?{?
????????String?encoding?=?null;?
????????if?(Configuration.isSet(WebWorkConstants.WEBWORK_I18N_ENCODING))?{?
????????????encoding?=?Configuration.getString(WebWorkConstants.WEBWORK_I18N_ENCODING);?
????????}?
????????Locale?locale?=?null;?
????????if?(Configuration.isSet(WebWorkConstants.WEBWORK_LOCALE))?{?
????????????locale?=?LocalizedTextUtil.localeFromString(Configuration.getString(WebWorkConstants.WEBWORK_LOCALE),?request.getLocale());?
????????}?
????????if?(encoding?!=?null?&&?!MultiPartRequest.isMultiPart(request))?{?
????????????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?
????????}?
????}
我看了jira沒有發(fā)現(xiàn)encoding != null && !MultiPartRequest.isMultiPart(request)這個判斷的意義。但是它會造成對multiPartRequest的encoding判斷失敗,中文就會亂碼。
所以臨時的解決方案是將判斷改成:
if (encoding != null)
聽說WW的Jira已經(jīng)不接受新issue了,不知是否真的?