好的,所以我试图在 jsp 页面上显示图像以及用户的名字和姓氏,但我只得到图像而不是名字和姓氏......那么这里有什么问题?...您的帮助将不胜感激:)
<%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
<%@ 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=windows-1256">
<title>Insert title here</title>
</head>
<body>
<H1>Fetching Data From a Database</H1>
<%
Blob image = null;
byte[] imgData = null;
Connection con;
String url="jdbc:mysql://localhost:3306/image";
String uName="root";
String pwd="root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(url,uName,pwd);
String sql="Select * from image ";
PreparedStatement stmt=con.prepareStatement(sql);
ResultSet resultset=stmt.executeQuery();
while(resultset.next())
{
Blob bl = resultset.getBlob("image");
byte[] pict = bl.getBytes(1,(int)bl.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
%>
<TABLE BORDER="1">
<TR>
<TH>First Name</TH>
<TH>Last Name</TH>
<TH>picture</TH>
</TR>
<TR>
<td>Image</td><td><%o.write(pict);%></td>
<%o.flush();
o.close();%>
<TD> <%= resultset.getString(2) %> </TD>
<TD><%= resultset.getString(3) %></TD>
</TR>
</TABLE>
<BR>
<%
o.flush();
o.close();
}
%>
</body>
</html>