Rendering images as a slideshow which are stored in the database as longblob
We have developed a small web application using spring and hibernate.Our application has a functionality of uplodaing the images and videos and we are storing the images and videos in the database in longblob format.
We are trying to display these images as a slideshow using an already existing javascript based "Simple Controls Gallery" http://www.dynamicdri开发者_如何转开发ve.com/dynamicindex4/simplegallery.htm which is found on the internet.I have tried to call a html page which will be redirected to a jsp page by the controller as follows :
var Imagearray1 = [
<c:set var="count" value="0"/>
<c:set var="comma" value=","/>
<c:forEach items="${imageList}" var="image" varStatus="loop">
<c:set var="count" value="${count + 1}"/>
[$.get('imagedisplay.html');,'http://','${image.imageTitle}','${image.imageDescription}']<c:if test="${fn:length(imageList) != count}"> <c:out value="${comma}"/> </c:if>
</c:forEach>
];
where imageList is the list of images from the database. You can see the actual code of Imagearray1 in the link that i mentioned.
How can i display the images using this gallery ?(or) if there is any other way of displaying images as a slidehow please explain it to me.
You need to create a servlet which streams the image content from the DB to the HTTP response, along a set of proper response headers. The nonsensicial $.get('imagedisplay.html');
ajax call must be replaced by an URL to the servlet which returns the image, e.g.
var images = [
<c:forEach items="${images}" var="image" varStatus="loop">
['imageservlet/${image.id}', '', '${image.imageTitle}', '${image.imageDescription}']${!loop.last ? ',' : ''}
</c:forEach>
];
Map your image servlet on an URL pattern of /imageservlet/*
and get the image ID (or filename) by request.getPathInfo()
and finally select it as InputStream
from the DB and write it to OutputStream
of the response. You can find a basic example in this answer: How to retrieve and display images from a database in a JSP page?.
精彩评论