我试过这段代码使用blob显示来自MySQL数据库的图像...图像不可见。我用过这段代码。
请纠正这个错误
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<img src="WEB-INF/New folder/birthhappy birthday.jpeg"
width="65" height="71" alt="birthhappy birthday"/>
<H1>Database Lookup</H1>
<FORM ACTION="base.jsp" METHOD="POST">
Please enter the ID of the publisher you want to find:
<BR>
<input type="text" name="imagename">
<BR>
<INPUT TYPE="SUBMIT" value="Submit">
</FORM>
</body>
</html>
base.jsp:
<%@page import="java.io.OutputStream"%>
<%@ page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/searchimg","root","");
Statement stmt = con.createStatement();
//String id = request.getParameter("id");
String imagename=request.getParameter("imagename");
ResultSet resultset =stmt.executeQuery("select * from friendupload where imagename = '" +imagename.trim()+ "' ") ;
while(resultset.next())
{
%>
<table>
<tr>
<td> <%=resultset.getString(1)%> </td>
<td> <%=resultset.getString(2) %> </td>
<td> <%=resultset.getString(3)%> </td>
<td>
Blob getimg=rs.getBlob( 4);
InputStream readImg = getimg.getBinaryStream();
int size=readImg.available();
OutputStream outf=new FileOutputStream("D:/profile/"+rs.getString(2)+rs.getString(3)+".jpeg");
byte b[]= new byte[size];
readImg.read(b);
outf.write(b);
outf.close();
</td>
</tr>
</table>
<% }%>
</form>
</body>
</html>