permaculture playing cards*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 744
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: 60800

Yes. Please see the JSP FAQ.

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

Joined: Apr 11, 2005
Posts: 744
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
It is sorta covered in the JavaRanch Style Guide.
subject: Uploading a image
Similar Threads
Nubmer of servlet instance
Running a servlet on Tomcat using Eclipse
Servlet Contrlloer Path Issue
tomcat can't find servlet
Basic Servlet question