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"
                           url="jdbc:mysql://localhost:3306/store"
                           user="root"/>

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

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

            <c:otherwise>
                 <table id="mainTable">
                <c:forEach var="row" items="${result.rows}">
                   
               <tr>
                   <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>
               </tr>
               
           
                </c:forEach>
</table>
            </c:otherwise>
        </c:choose>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.