0
我找不到使用jsp.What我想为下面的代码img标签为GET BLOB图片从数据库解决方案和显示,如何让img标签的blob图像JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border=1>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:mysql://localhost:3306/raptor1_5","root","");
Statement st=connection.createStatement();
ResultSet rst = st.executeQuery("select * from contacts");
while(rst.next())
{
Blob image = rst.getBlob("Images");
byte[ ] imgData = null ;
imgData = image.getBytes(1,(int)image.length());
String answer = rst.getString("Answers");
//response.setContentType("image/gif");
//OutputStream o = response.getOutputStream();
%>
<tr>
<td><img src="<%=imgData %>" alt="images Here" width="130px" height="90px"></td>
<td><%=answer %></td>
</tr>
<%}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</body>
</html>
我试过很多问题像<img>
从数据库检索blob文件,但我不明白如何显示。所以请别人告诉我如何使用jsp动态地在<img>
标记中获取斑点图像。
我希望有人能帮助我... ..!
如果我用 MMMMS 2015-01-21 11:05:23
即使我试过 MMMMS 2015-01-21 11:22:12
检查编辑的答案 – 2015-01-21 11:28:06