Search code examples
javajspjakarta-eeservlets

Display Image on web page using Java


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 ?


Solution

  • 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.