jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes FileUpload size limit error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "FileUpload size limit error" Watch "FileUpload size limit error" New topic

FileUpload size limit error

Chris Hogg

Joined: Dec 10, 2003
Posts: 5
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:
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
try {
List items = upload.parseRequest(req);
results = ub.saveFiles(UploadRoot, items);
session.setAttribute("results", results);
catch (FileUploadException ue) {
logger.error("doPost: File Upload error");
showView(req, resp, "/Error.jsp");
catch(OutOfMemoryError me) {
throw me;
showView(req, resp, "/UploadResults.jsp");
Has anyone else hit this problem who is using it or have any suggestions on how to get by it?

Thanks, Chris
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
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

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Chris Hogg

Joined: Dec 10, 2003
Posts: 5
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: FileUpload size limit error
It's not a secret anymore!