2

In my Java EE app, there is a function to upload images. When uploading an image, I'm saving image path in MySQL database.

Now I want to display uploaded image on a web page using image path that saved when uploading the image in my MySQL database table.

How could I do this ?

2 Answers 2

3

It depends. Is the path someplace that a web server is serving documents from? Then just include the path, adjusted as necessary, in an IMG tag. If not, or if the image data itself is actually in the database (you're not entirely clear about this) then create a servlet which returns the contents of an image based on query parameters, and use that servlet's URL (plus the query parameters) in the SRC attribute of the IMG tag.

Sign up to request clarification or add additional context in comments.

Comments

3

Write a servlet that extracts your stored image from database and writes back into servlet outputstream.
You need to set the relevant mime type of the image, for example "image/jpeg", before writing into outputstream.

You need to point the image source to this servlet url with required input parameters to load the correct image from the database. For example :

<img src="http://mydomain/servlet/imageServlet?imgid=xyz" />

There is nice example given by BalusC at: ImageServlet serving from database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.