We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Question about use of apache fileupload?

EmailSurfer
EmailSurfer asked
on
Medium Priority
711 Views
Last Modified: 2008-03-06
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
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
What do you mean by "send the files back to the JSP" ?

You mean just the names of the files?

Author

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?
CERTIFIED EXPERT
Top Expert 2004
Commented:
You can't (I don't believe)

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

Tim

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks

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

<p align="center"><input type="file" size="45" name="filename1"></p>
CERTIFIED EXPERT
Top Expert 2004

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

Nope...  Try it...  it doesn't work...

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.