![数据库里存储的图片字段定义类型为blob,java里对应的类型为byte[],怎么将图片显示到jsp页面??,第1张 数据库里存储的图片字段定义类型为blob,java里对应的类型为byte[],怎么将图片显示到jsp页面??,第1张](/aiimages/%E6%95%B0%E6%8D%AE%E5%BA%93%E9%87%8C%E5%AD%98%E5%82%A8%E7%9A%84%E5%9B%BE%E7%89%87%E5%AD%97%E6%AE%B5%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%9E%8B%E4%B8%BAblob%EF%BC%8Cjava%E9%87%8C%E5%AF%B9%E5%BA%94%E7%9A%84%E7%B1%BB%E5%9E%8B%E4%B8%BAbyte%5B%5D%EF%BC%8C%E6%80%8E%E4%B9%88%E5%B0%86%E5%9B%BE%E7%89%87%E6%98%BE%E7%A4%BA%E5%88%B0jsp%E9%A1%B5%E9%9D%A2%EF%BC%9F%EF%BC%9F.png)
jsp编程从数据库中取出
1、读取数据testimageoutjsp文件
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="javasql" %>
<%@ page import="javautil" %>
<%@ page import="javatext" %>
<%@ page import="javaio" %>
<html>
<body>
<%
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection con=DriverManagergetConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=concreateStatement();
ResultSet rs=null;
int id=IntegerparseInt(requestgetParameter("id"));
String sql = "select image from picturenews where id='"+id+"'";
rs=stmtexecuteQuery(sql);
while(rsnext())
{
ServletOutputStream sout = responsegetOutputStream();
InputStream in = rsgetBinaryStream(1);
byte b[] = new byte[0x7a120];
for(int i = inread(b);i!=-1)
{
soutwrite(b);
inread(b);
}
soutflush();
soutclose();
}
%>
<body>
</html>
2、取出所要显示的showimagejsp文件
<%@ page contentType="text/html;charset=bg2312"%>
<%@ page import="javasql" %>
<html>
<head>
<title>显示数据库测试页</title>
</head>
<body>
<%
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection con=DriverManagergetConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=concreateStatement();
String sql=new String();
sql = "select id from picturenews";
ResultSet rs=stmtexecuteQuery(sql);
//显示最后一条记录的
rslast();
%>
<table>
<tr><td><img src='testimageoutjspid=<%=rsgetInt("id")%>'></td></tr>
</table>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)