in jsp, is HttpServletRequest mutable throught out all pages? (commons fileupload issue)

136 views Asked by At

when setting a file size limit on commons fileupload (diskfileupload class) to for example 10MB, when uploading a file that is more than 10MB, diskfileupload will throw a sizelimitexceededexception, with this I had a response.redirect("previous webpage") on the catch exception like the ff:

try{
 DiskFileUpload dfu = new DiskFileUpload();
 dfu.setSizeThreshold(4096);                
 dfu.setSizeMax(10 * 1024 * 1024);       
 dfu.setRepositoryPath(tempDir);  
 // get form values here after parse
 java.util.List formItems = dfu.parseRequest(request);

 ... some form params (shorten code)
 String userName = formItems.get("userName");
 if(userName.isEmpty()){
   response.redirect("/addUser?error=username cannot be empty");
 }
}catch(Exception e){
 if(e.toString().contains("SizeLimitExceededException")){
   response.redirect("/addUser?error=cannot upload more than 10MB file sise");
 } else {
   throw e;
 }
}

the problem is, when I am not uploading anything, just response redirect to to the addUser page when userName is empty, I can still get the old values of other field and show the error message, but when I upload a file that exceed the 10MB limit, when redirect back to addUser, all the old values are gone, and sometimes i see the content header is missing error.

what am I doing wrong?

0

There are 0 answers