|
Sponsored Links
Resources
Enterprise Java Research Library
Get Java white papers, product information, case studies and webcasts
|
Web tier: servlets, JSP, Web frameworks
Web tier: servlets, JSP, Web frameworks
Web tier: servlets, JSP, Web frameworks
|
Messages: 1
Messages: 1
Messages: 1
Printer friendly
Printer friendly
Printer friendly
Post reply
Post reply
Post reply
XML
XML
XML
|
 |
How to Display Images in JSP retrieved from database using blob
hi
i want to display the image stored in the database, i am storing as blob, i am able to retrieve the image and i want to display it in the jsp page , can u just give either the code or sample how to do it.
thanks in advance
srini
|
|
Message #17482
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
How to Display Images in JSP retrieved from database using blob
Hello Srini.
Take a look at the following JSP Page. Important ist the setting of the ContentType for the response header, i.e. to "image/gif" or "image/jpeg" (in this case a database field, too).
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
Class.forName("com.inet.tds.TdsDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:inetdae7:encharmion_nt4?database=RS", "Vignette", "vignette");
String strSQL = "SELECT ContentType, ImageBinary "
+ "FROM Images "
+ "WHERE (ImageID=" + request.getParameter("imageid") + ")";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(strSQL);
rs.next();
response.setHeader("expires", "0");
response.setContentType(rs.getString("ContentType"));
out.clear();
OutputStream os = response.getOutputStream();
os.write(rs.getBytes("ImageBinary"));
out.flush();
return;
%>
This is only a test page, of course you should use some kind of connection pooling etc. in production sites.
Stefan
|
|
 |
Hot threads
Hot threads
Hot threads
|
More hot threads
More hot threads
More hot threads
|
 |
Brian Goetz continues to lift the lid and peak into the inner workings of Java in Java Urban Performance Legends. In this article he exposes the fallacy behind some of the more common performance myths found in the annals of the JVM.
(92 comments,
last posted
March 14, 2008)
Bruce Tate, author of Better, Faster Lighter Java and Bitter EJB has come out with a new book called Beyond Java. Bruce has an epiphany about the future of software development. Does it include Java?
(770 comments,
last posted
September 23, 2009)
Looks like today AJAX concept have several interpretations. We can distinguish different approaches of AJAX integration. Can they co-exist within the same application? Can we talk about layered AJAX integration?
(68 comments,
last posted
May 08, 2008)
Artima has published a short article describing the Design-Time API for JavaBeans, which was recently approved as JSR 273. This API promises to bring VB-like ease to Java development, but may face a cultural bias among Java developers who tend to think more in terms of class libraries than components.
(226 comments,
last posted
February 01, 2010)
There is plenty of speculation today regarding a potential buyout of Sun Microsystems by Scott McNealy and Silver Lake Partners. How would privatization of Sun affect Java?
(16 comments,
last posted
May 15, 2009)
More hot threads »
|
|