File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Uploading a image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Uploading a image" Watch "Uploading a image" New topic

Uploading a image

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi there, supposing you have an HTML page (or jsp, or servlet)
with the code:

And supposing the file was an image(jpg or bmp or something else),
is it possible to get the SomeServlet servlet to store the image
in a folder, to be used later on in the web application?

Thanks for any help
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Yes. Please see the JSP FAQ.

[Asking smart questions] [About Bear] [Books by Bear]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Thanks, I found an example...

but I dont get it. I won't have a list of items, just one file,
from 1 INPUT tag. Is it necessary in this case to use the
org.apache.commons package, or can I store 1 file without it?

dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Maybe you can get it just by name?

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The protocol supports multiple files in one upload. If you only have one it will still work just fine. I'd stick with the code as-is if it's working for you.

The Apache code is doing lots of tricky stuff for you. Browse the code or download Jason Hunter's MultiPartParser and see just how much. I wrote my own for a server that is not J2EE servlets, and it was a significant bit of work. For grins, also look at the Fitnesse server which does the same job in far fewer lines of code than any of those others.
[ March 17, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Uploading a image
It's not a secret anymore!