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

image upload

apurv suthar
Ranch Hand

Joined: Feb 05, 2012
Posts: 35
Hey frnds....i need help. I wants to make a jsp page that takes image from user and store it into the mysql database and use it on another jsp page.....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Welcome to the Ranch!

There are four separate problems here:
1) Send the image from the browser to the server. Use a form like this:
(Replace xxx as required)
This way the file data will be available on the server, as long as you handle it properly.

2) Read the image data on the server. Check out http://www.coderanch.com/how-to/java/FileUpload.

3) Put the image data into the database. Use a PreparedStatement with setBinaryStream.

4) Show the image. You shouldn't do this directly using a JSP; those are not meant for binary data. Instead, use a servlet to display the image. In the JSP you can use a simple <img> tag with the src attribute set to the servlet (possibly with parameters). For example:
getimage is then a URL mapping to the servlet. This servlet takes the id parameter and uses it to retrieve and output the image data.


Oh, and please UseRealWords: "friends", not "frnds".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
apurv suthar
Ranch Hand

Joined: Feb 05, 2012
Posts: 35
Thank you for your help....It's quite helpful...and I will take care of following standard of using realword!!!haha
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image upload