//struts中的action对应的actionform一定要随便写一个不存在的actionform,否则,进入action之后, struts可能对request作了什么操作,使得无法应用MultipartRequest
String filePath = request.getRealPath("/") + "docfile";// 上传到指定的docfile包中
filePath = filePath.replace(".//", "//");
File testFolder = new File(filePath);
if (!testFolder.exists()) {
try {
testFolder.mkdir();
} catch (Exception e) {
throw new Exception("无法创建附件存放文件夹");
}
}
share.tools.servlet.MultipartRequest mr=new share.tools.servlet.MultipartRequest(request, testFolder.getAbsolutePath(), Integer.MAX_VALUE,
"gbk", new DefaultFileRenamePolicy());//执行这个之后就会上传文件了
filedvalues[i]= mr.getParameter(filednames[i]);//获取字段值
multipartrequest 下载地址http://www.servlets.com/cos/index.html