This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "FileUpload size limit error" Watch "FileUpload size limit error" New topic
Author

FileUpload size limit error

Chris Hogg
Greenhorn

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:
<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?


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
Greenhorn

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
 
Similar Threads
Eror 500- Server are not find the jar file in the program of upload the file
Upload Image to database through Servlet
current thread not owner
To know about File Upload
file uploading to db using servlet