commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ha Pham <>
Subject Re: fileUpload causes getRequestDispatcher(url).forward hanging
Date Wed, 07 Jan 2009 21:30:36 GMT
Thanks for your response.

I actually did not directly invoke request dispatcher within a try/catch. That happens in
another servlet, and it works fine in other cases. I just put together for shorten the code
in my email.

>Second, remember that FileUpload will have consumed the input stream, so
>that it will no longer be available to any servlet that you forward to.

Is this a bug in fileUpload? Should it release all resources when exceptions happen? Is there
any way that we can have FileUpload release the input stream? 


From: Martin Cooper <>
To: Commons Users List <>
Sent: Wednesday, January 7, 2009 2:14:43 PM
Subject: Re: fileUpload causes getRequestDispatcher(url).forward hanging

First, you are invoking the request dispatcher from inside a catch clause,
which is a really bad idea (if it even works).

Second, remember that FileUpload will have consumed the input stream, so
that it will no longer be available to any servlet that you forward to.

Martin Cooper

On Wed, Jan 7, 2009 at 12:42 PM, Ha Pham <> wrote:

> Dear all,
> I have a small snippet of code as below
>           DiskFileItemFactory  factory = new DiskFileItemFactory();
>           ServletFileUpload upload = new ServletFileUpload(factory);
>            // maximum size that will be stored in memory
>            factory.setSizeThreshold(10240);
>            // the location for saving data that is larger than
> getSizeThreshold()
>            factory.setRepository(new
> File(System.getProperty("specFolderOnServer")));
>            // maximum size before a FileUploadException will be thrown
>  upload.setSizeMax(Integer.parseInt(System.getProperty("maxUploadFileSize")));
>            // Parse the request
>            List<FileItem> items ;
>            try {
>                items = upload.parseRequest(request);
>            } catch (FileUploadException fue) {
>               request.getRequestDispatcher(url).forward(request, response);
>            }
> When I uploaded a file that exceeds limit size, the program hung at
> request.getRequestDispatcher(url).forward(request, response);
> I did some research and found that it relates to the session locking
> somehow, but I could not find a clear suggestion on how to have it resolved.
> Could anyone help me with this issue?
> I currently have to remove the line  upload.setSizeMax and check filesize
> limit manually by using method getSize in class FileItem. However, I have a
> feeling that it's more efficient to set max file size in ServletFileUpload
> as the system may not need to copy/save the uploaded file if its size
> exceeds the preset limit. Is this true?
> Thank you,
> Ha

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message