• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

Question about use of apache fileupload?

Hello,

Could anyone advise, if I use this code in a servlet to recieve input from a jsp.

         FileItemFactory factory = new DiskFileItemFactory();
         ServletFileUpload upload = new ServletFileUpload(factory);
         List items = upload.parseRequest(req);

If I wanted to return the files back to the jsp, for example if there was some error with the input. Could any demonstrate how I could send back the files to the jsp, and show them in the orginal jsp?

Thanks
0
EmailSurfer
Asked:
EmailSurfer
  • 3
  • 3
1 Solution
 
TimYatesCommented:
What do you mean by "send the files back to the JSP" ?

You mean just the names of the files?
0
 
EmailSurferAuthor Commented:
Hello,

When the user uploads the files, in the servlet I test if the file size is >0.

And if not, I thought I should return to the upload jsp page with an error message for the user. And the orginal filenames displayed back in the html input fields.

<p align="center"><input type="file" size="45" name="filename1"></p>
<p align="center"><input type="file" size="45" name="filename2"></p>

In the servlet I use this code to access the files.

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(req);

If the files are tested as being < 0 in size, would I use theapache fileupload getName() method in the servlet to get the file path, and return this back to the fileupload jsp?

I hope this makes sense?
0
 
TimYatesCommented:
You can't (I don't believe)

For security reasons, you have very little control over type="file" objects...

Tim
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
EmailSurferAuthor Commented:
Thanks

In the input type="file" we cannot use value=""?

<p align="center"><input type="file" size="45" name="filename1"></p>
0
 
TimYatesCommented:
>> In the input type="file" we cannot use value=""?

Nope...  Try it...  it doesn't work...
0
 
EmailSurferAuthor Commented:
Thank you,

Could I finally ask, in my web application I allow the user to select through an html form to post in there account.

I thought when storing the files on the server, I should check if the filename is already used. And if the filename is used add a number to the begining or end of the filename and check again if this new filename exists. And then store the file on the server. Do you think is the easist approach to saving files on the server with the same name.

Thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now