|
Java™ by example!
|
|
|
How do I deliver an image stored in mysql with a servlet?
To answer this, I created a table images in a test database and stored the esus logo in it.
To save an image in this table, use the following code and specify the image at command line. Use a JPG image, as the MIME content type for the servlet we'll write will be image/jpeg. Main.java:
The servlet that delivers the image to the browser looks just like any other one, except that the MIME content-type attribute is set to image/jpeg (use image/gif for GIF files). The rest of the code handles the reading of the image from the mysql table given its unique index. Servlet GetImage.java:
You can now use the reference to this servlet in an img src HTML tag:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|