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
EmailSurferAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.