jsp如何从oracle数据库中读取blob类型图片并在table中的一个单元格显示
相应程序如下:显示界面的showpicture.jsp:<table><tr><td><imgsrc=<%="getpicture.jsp?fileid="+fileid...
相应程序如下:
显示界面的showpicture.jsp:
<table ><tr><td ><img src=<%="getpicture.jsp?fileid="+fileid %> width="350" height="250"></td></tr></table>
获取数据库中的图片getpicture.jsp
String fileid=request.getParameter("fileidid");
String sql="select id,htmname,htmcont from htm ";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "shallwe","shallwe");
conn.setAutoCommit(false); //连接数据库
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next()) {
if(rs.getString(1).equals(fileid))
{
OutputStream outs= null;
Blob blob = rs.getBlob("htmcont");
long size = blob.length();
byte[] b = blob.getBytes(1,(int)size);
outs = response.getOutputStream();
outs.write(b);
outs.flush(); //从数据库获取blob类型图片并输出
outs.close();
outs = null; }
rs.close();
rs=null;
pstmt.close();
pstmt=null;
conn.close();
conn = null; }
问题:单独运行getpicture.jsp,可以在网页中显示图片,可是用showpicture.jsp调用却不行,这是为什么?如何解决? 展开
显示界面的showpicture.jsp:
<table ><tr><td ><img src=<%="getpicture.jsp?fileid="+fileid %> width="350" height="250"></td></tr></table>
获取数据库中的图片getpicture.jsp
String fileid=request.getParameter("fileidid");
String sql="select id,htmname,htmcont from htm ";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "shallwe","shallwe");
conn.setAutoCommit(false); //连接数据库
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next()) {
if(rs.getString(1).equals(fileid))
{
OutputStream outs= null;
Blob blob = rs.getBlob("htmcont");
long size = blob.length();
byte[] b = blob.getBytes(1,(int)size);
outs = response.getOutputStream();
outs.write(b);
outs.flush(); //从数据库获取blob类型图片并输出
outs.close();
outs = null; }
rs.close();
rs=null;
pstmt.close();
pstmt=null;
conn.close();
conn = null; }
问题:单独运行getpicture.jsp,可以在网页中显示图片,可是用showpicture.jsp调用却不行,这是为什么?如何解决? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询