I'm trying to upload a .csv file from a JSP to a servlet. It works perfectly on my local machine (Java 1.8 on Websphere 8.5.5.11), but when I move it to test environments (Java 1.6 on WebSphere 8.5.5.12), I get an error that says:
java.lang.UnsupportedOperationException: SRVE8020E: Servlet does not accept multipart requests
Which seems odd, because isMultipart comes back as true.
Here is my JSP form:
<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>
Here is my 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));
}
}
I've tried setting Eclipse to compile this project using Java 6, with no luck. As far as I know, I can't set my local WebSphere instance to run using 1.6. I tried using Apache Commons FileUpload and Commons IO instead of doing it natively through Java with no luck, and am starting to consider figuring out how to parse the request manually.
Anyone have any idea what's going on, or any ideas for things I should try? I've browsed through these questions and answers already:
How to upload files to server using JSP/Servlet?
Convenient way to parse incoming multipart/form-data parameters in a Servlet
How can I read other parameters in a multipart form with Apache Commons
How to upload files to server using JSP/Servlet?
Thanks in advance for any help or ideas.