aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Uploading a image" Watch "Uploading a image" New topic
Author

Uploading a image

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 743
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
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

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: 743
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?

Thanks
dema rogatkin
Ranch Hand

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


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" 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: http://aspose.com/file-tools
 
subject: Uploading a image
 
Similar Threads
Basic Servlet question
Servlet Contrlloer Path Issue
Running a servlet on Tomcat using Eclipse
tomcat can't find servlet
Nubmer of servlet instance