我正在尝试将 .csv 文件从 JSP 上传到 servlet。它在我的本地机器上完美运行(Websphere 8.5.5.11 上的 Java 1.8),但是当我将它移动到测试环境(WebSphere 8.5.5.12 上的 Java 1.6)时,我收到一条错误消息:
java.lang.UnsupportedOperationException: SRVE8020E: Servlet 不接受多部分请求
这看起来很奇怪,因为 isMultipart 返回为真。
这是我的 JSP 表单:
<form method="POST" name="batchForm" action="BatchTierProcessing" enctype="multipart/form-data">
<input type="hidden" name="pageName" value="batchTierProcess"/>
<text>Upload File for Batch Processing:</text>
<input type="file" name="file" id="file"/>
<input type="submit" value="Upload" name="upload" id="upload"/>
</form>
这是我的 servlet:
@WebServlet(name = "UWTSAS", urlPatterns = {"/UWTSAS"}, loadOnStartup = 1)
@MultipartConfig
public class PMSTandalone extends AWRServlet {
@Override
protected void doPost(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(aRequest);
FileItem csv = null;
String pageNameMultiPart = "";
Exception fakeException = new Exception();
PageNameEnum pageName = null;
Part filePart = null;
//if a multipart request (batch process) grab file before request is touched by anything else
if(isMultipart) {
LogMessageUtility.log("INFO", "Is multipart request", fakeException);
filePart = aRequest.getPart("file");
pageName = PageNameEnum.getValue("pmSABTS");
LogMessageUtility.log("INFO", "Page Name Multipart", fakeException);
}
else {
pageName = PageNameEnum.getValue(aRequest.getParameter("pageName"));
}
HttpSession aSession = aRequest.getSession(false);
if(aSession == null) {
aSession = aRequest.getSession(true);
}
buildUserSession(aRequest, aSession);
boolean batchSuccessful = true;
String destination = "PMStandBatchRes";
LogMessageUtility.log("INFO", "Batch Processing Started", fakeException);
try {
batchSuccessful = getFinalScoresBatch(aRequest, aResponse, aSession, filePart);
}
catch(Exception e) {
LogMessageUtility.log("ERROR", e.getMessage(), e);
}
}
if(!destination.equals("") && batchSuccessful) {
dispatchToResource(aRequest, aResponse, WebRatingProperty.getSetting(destination));
}
}
我已经尝试将 Eclipse 设置为使用 Java 6 编译这个项目,但没有成功。据我所知,我无法将本地 WebSphere 实例设置为使用 1.6 运行。我尝试使用 Apache Commons FileUpload 和 Commons IO,而不是在没有运气的情况下通过 Java 本地进行,并且开始考虑弄清楚如何手动解析请求。
任何人都知道发生了什么,或者对我应该尝试的事情有什么想法?我已经浏览了这些问题和答案:
在 Servlet 中解析传入的 multipart/form-data 参数的便捷方法
如何使用 Apache Commons 以多部分形式读取其他参数
在此先感谢您的任何帮助或想法。
我想到了。不得不移除@MultipartConfig 注解,并实现javax.servlet.Servlet 接口,并使用Apache Commons FileUpload 库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句