数据库里存储的图片字段定义类型为blob,java里对应的类型为byte[],怎么将图片显示到jsp页面??
1个回答
展开全部
我把我以前收集的给你贴出来,希望能对你有所帮助
jsp编程从数据库中取出图片
1、读取图片数据testimageout.jsp文件
<%@ page contentType="text/html;charset=gb2312"%
<%@ page import="java.sql.*" %
<%@ page import="java.util.*" %
<%@ page import="java.text.*" %
<%@ page import="java.io.*" %<html<body<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=con.createStatement();
ResultSet rs=null;
int id=Integer.parseInt(request.getParameter("id"));
String sql = "select image from picturenews where id='"+id+"'";
rs=stmt.executeQuery(sql);
while(rs.next()){ServletOutputStream sout = response.getOutputStream();
InputStream in = rs.getBinaryStream(1);
byte b[] = new byte[0x7a120];
for(int i = in.read(b);i!=-1){sout.write(b);
in.read(b);}sout.flush();
sout.close();}%<body</html2、取出所要显示的图片showimage.jsp文件
<%@ page contentType="text/html;charset=bg2312"%
<%@ page import="java.sql.*" %<html<head<title显示数据库图片测试页</title</head<body<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=con.createStatement();
String sql=new String();
sql = "select id from picturenews";
id=<%=rs.getInt("id")%'</td</tr</table</body</html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |