<%@page import="cn.java.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.text.*"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<!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>JSP Page</title>
</head>
<body>
<%
Connection conn = null;
Statement stmt=null;
ResultSet rs=null;
try {
String sql = "select ps from ss where id=15";
conn = DBUtil.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
response.setContentType("image/jpeg");
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);
}
//普通數據採用此語句
// while(in.read(b)!=-1){
// sout.write(b);//輸出字符流
/// }
sout.flush();
sout.close();//關閉sout輸出流
}
} catch (SQLException ex) {
out.println(ex.getMessage());
}
finally {
try {
DBUtil.close(rs, stmt, conn);
} catch (Exception ex) {
out.println(ex.getMessage());
}
}
%>
</body>
</html>