This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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: 19697
    
  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: 19697
    
  20

You're welcome
 
GeeCON Prague 2014
 
subject: image upload