Good day guys,
anyone here who knows how to easily access image pointers stored in a database in JSP?...

here's my code =) ... it already works in retrieving data other than the image...

my database contains petid, petname,birthdate,image,petprice....

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<sql:setDataSource driver="com.mysql.jdbc.Driver"

        <sql:query var="result" sql="SELECT petid, petname,birthdate,image,petprice FROM pets"/>

            <c:when test="${result.rowCount == 0}">
             <p> no more to display! </p>

                 <table id="mainTable">
                <c:forEach var="row" items="${result.rows}">
                   <td><h5><c:out value="${row.petid}"/></h5></td>
                <td><h5><c:out value="${row.petname}"/></h5></td>
                <td><h5><c:out value="${row.birthdate}"/></h5></td>
                <td><h5><c:out value="${row.image}"/></h5></td>
                <td><h5><c:out value="${row.petprice}"/></h5></td>
6 Years
Discussion Span
Last Post by parry_kulk

If the image is stored as blob binary data you cannot display it is using simply the c:out tag.

You need to create a servlet which streams the image from the server and call it in img tag as something like
<img src="/getImage?petid=${row.petid}" />

Now in the servlet
1. Read the blob image from the database table into a stream.
2. Set the response MIME type for the image ->
response.setContentType("image/jpeg") or whatever the image type may be.
3. Open the response output stream and write the image stream into it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.