Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileUpload size limit error

 
Chris Hogg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using apache commons FileUpload to upload files of up to 20 MB. I set the limit at 20 MB and during DiskFileUpload.parse the error is caught when I try to upload a file that is too large.
However, when I try to forward to a JSP from my servlet, I'm getting an error:
java.lang.IllegalStateException: Cannot forward a response that is already committed
The source looks like the following:
<code>
boolean isMultipart = FileUpload.isMultipartContent(req);
logger.info("multipart session: " + isMultipart);
if (isMultipart) {
// Request is to upload files
UploadBean ub = (UploadBean) session.getAttribute("ub");
Vector results = new Vector();
if (ub == null) {
// First time loading the page so create the bean
// then put it into the session so we don't have to
// create a new one with each call.
ub = new UploadBean();
session.setAttribute("ub", ub);
}
DiskFileUpload upload = new DiskFileUpload();
// Set upload parameters
upload.setRepositoryPath(TempPath);
upload.setSizeMax(user.getMaxFileSize());
upload.setSizeThreshold(4096);
try {
List items = upload.parseRequest(req);
results = ub.saveFiles(UploadRoot, items);
session.setAttribute("results", results);
}
catch (FileUploadException ue) {
logger.error("doPost: File Upload error");
logger.error(ue.getMessage());
showView(req, resp, "/Error.jsp");
}
catch(OutOfMemoryError me) {
logger.error(me.getMessage());
throw me;
}
showView(req, resp, "/UploadResults.jsp");
</code>
Has anyone else hit this problem who is using it or have any suggestions on how to get by it?
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that error means you've done something already that committed a response to the user. you can try request.reset() before forwarding or trying to find out what you did to commit the response and doing that at a later stage after the potential forward
 
Chris Hogg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip. I ended up throwing a new error in the catch clause and then configuring an error page (FileSizeError.jsp) for the error I threw (FileUploadException) in the web.xml <error-page> element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic