修复方案:
升级struts2版本:
产生影响:
文件上传报错:Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (cos)
修复方案:
1.将cos的jar包下载并放置WEB-INF/lib内
2.创建一个org.apache.struts2.dispatcher.multipart.MultiPartRequest的实现类
package com.nuchina.common.util;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import com.opensymphony.xwork2.inject.Inject;
import com.oreilly.servlet.MultipartRequest;
public class CosMultiPartRequest implements MultiPartRequest {
private MultipartRequest multi;
private String defaultEncoding;
private boolean maxSizeProvided;
private int maxSize;
@Inject(StrutsConstants.STRUTS_I18N_ENCODING)
public void setDefaultEncoding(String defaultEncoding) {
this.defaultEncoding = defaultEncoding;
}
@Inject(StrutsConstants.STRUTS_MULTIPART_MAXSIZE)
public void setMaxSize(String maxSize) {
this.maxSizeProvided = true;
this.maxSize = Integer.parseInt(maxSize);
}
@Override
public String[] getContentType(String fieldName) {
return new String[] { multi.getContentType(fieldName) };
}
@SuppressWarnings("unchecked")
@Override
public List getErrors() {
return Collections.EMPTY_LIST;
}
@Override
public File[] getFile(String fieldName) {
return new File[] { multi.getFile(fieldName) };
}
@Override
public String[] getFileNames(String fieldName) {
return new String[] { multi.getFile(fieldName).getName() };
}
@SuppressWarnings("unchecked")
@Override
public Enumeration<String> getFileParameterNames() {
return multi.getFileNames();
}
@Override
public String[] getFilesystemName(String name) {
return new String[] { multi.getFilesystemName(name) };
}
@Override
public String getParameter(String name) {
return multi.getParameter(name);
}
@SuppressWarnings("unchecked")
@Override
public Enumeration<String> getParameterNames() {
return multi.getParameterNames();
}
@Override
public String[] getParameterValues(String name) {
return multi.getParameterValues(name);
}
@Override
public void parse(HttpServletRequest request, String saveDir) throws IOException {
if (maxSizeProvided) {
multi = new MultipartRequest(request, saveDir, maxSize, defaultEncoding);
} else {
multi = new MultipartRequest(request, saveDir, defaultEncoding);
}
}
@Override
public void cleanUp() {
// TODO Auto-generated method stub
}
}
---------------------
作者:雨夜星辰03
来源:CSDN
原文:https://blog.csdn.net/qwerty1994/article/details/62422697
版权声明:本文为博主原创文章,转载请附上博文链接!
3.添加配置
<!-- 配置cos文件上传的解析器 -->
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="cos" class="com.xxxxx.common.util.CosMultiPartRequest" />
<!--避免编号为CVE-2017-5638的该漏洞,-->
<!--影响系统及版本:Struts 2.3.5 - Struts 2.3.31、Struts 2.5 - Struts 2.5.10-->
<constant name="struts.multipart.parser" value="cos"></constant>