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="" prefix="c"%>
<%@taglib uri="" 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>

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, learning, and sharing knowledge.