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? 

Thanks,
Ha





________________________________
From: Martin Cooper <[email protected]>
To: Commons Users List <[email protected]>
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 <[email protected]> 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
>

Reply via email to