The moose likes Servlets and the fly likes image upload Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "image upload" Watch "image upload" New topic
Author

image upload

apurv suthar
Greenhorn

Joined: Feb 05, 2012
Posts: 11
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18374

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
How To Ask Questions How To Answer Questions
apurv suthar
Greenhorn

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

Joined: Oct 27, 2005
Posts: 18374

You're welcome
 
 
subject: image upload
 
Threads others viewed
Ho to display image getting from byte array in JSP ?
Insert jpeg files in the database column
store an image to database and also retrieve
how to upload an image through jsp
thumbnail in jsp
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com