`
Tin
  • 浏览: 137323 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

WebWork 2.2.2中文上传乱码问题[临时解决方案]

阅读更多
使用jakarta commons-upload。
升级到2.2.2后发现上传中文会乱码。
经过跟踪发现在com.opensymphony.webwork.dispatcher.DispatcherUtils的prepare(HttpServletRequest request, HttpServletResponse response)方法。
2.2.1->2.2.2时这个方法发生了非常的的变化。
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没有发现encoding != null && !MultiPartRequest.isMultiPart(request)这个判断的意义。但是它会造成对multiPartRequest的encoding判断失败,中文就会乱码。
所以临时的解决方案是将判断改成:
if (encoding != null)

听说WW的Jira已经不接受新issue了,不知是否真的? Crying or Very sad
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics