I have a file upload applet in my jsf page. This applet expects an adress where it can send it's POST request. (I can't edit this post request to add more fields or something). The post method of my servlet then stores the file. This job can't be done by a managed bean because the servlet has to be annotated with @MultiPartConfig and I can't add this annotation to the jsf managed bean. In order to force the upload applet to use the same session I added an URL attribute named jsessionId to the post request according to this topic. Now whenever I try to upload more than one file during a session the applet stops with the error message "The regexp string "^SUCCESS$" was not found in the response body" this is because the applet expects this string in the servlets response in order to know that the upload was successfull.
When I view the debug code of the applet the response contains a lot of html code but not this success string altough I add it in my Servlet code. Here's the code of my servlet :
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.reset();
if (!userBean.getUploadedDatasets().isEmpty()) {
String datasetID = userBean.getUploadedDatasets().getLast().replaceAll("/", "%2F");
response.sendRedirect(response.encodeRedirectURL("http://____________/faces/details.xhtml?id="+datasetID));
}
}
/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response){
PrintWriter out = null;
try {
Part filePart = request.getPart("item");
InputStream filecontent = filePart.getInputStream();
String datasetID = repBean.persistDataset(filecontent, uploadBean.getFolder());
userBean.getUploadedDatasets().add(datasetID);
out = response.getWriter();
out.println("SUCCESS");
} catch (ServletException ex) {
Logger.getLogger(RequestHandler.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(RequestHandler.class.getName()).log(Level.SEVERE, null, ex);
}finally{
out.close();
}
}
the doGet method is used as afterUploadURL by the applet (so that's the url to which is jumped after a file is uploaded)
the applet code is :
<APPLET
CODE="wjhk.jupload2.JUploadApplet"
NAME="JUpload"
ARCHIVE="wjhk.jupload.jar"
WIDTH="640"
HEIGHT="300"
MAYSCRIPT="true"
ALT="The java pugin must be installed.">
<param name="postURL" value="http://________________/request;jsessionid=#{session.id}" />
<!-- Optionnal, see code comments -->
<param name="showLogWindow" value="false" />
<param name="debugLevel" value="99" />
<param name="httpUploadParameterName" value="item" />
<param name="nbFilesPerRequest" value="1" />
<param name="httpUploadParameterType" value="oneFile" />
<param name="afterUploadURL" value="http://________________/request" />
</APPLET>
and after trying to upload a second file, the "old" (that's what I think but I don't know enough about servlets) response looks like this : http://pastebin.ca/2300999 (too many characters so I had to upload it there)