show.jsp //照片顯示頁面
<%@ page contentType="text/html;charset=GBK"%>
<%@ page session="true" import="yx.mainframe.*,java.sql.*,org.thcic.db.*" %>
<%@ page import="java.util.*,java.io.*" %>
<%@ page import="yx.utils.JPEGImageTXM" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body >
<%
String xh = request.getParameter("xh");
DBSource dbSource = new DBSource();
InputStream in = null;
OutputStream os = response.getOutputStream();
try{
String sql = "select photo from xj_xjb_view where xh = '" + xh + "'";
ResultSet rs = dbSource.executeQuery(sql);
while(rs.next()){
in = rs.getBinaryStream("photo");
if(in == null){
response.sendRedirect("./07.gif");
return;
}
response.reset();
response.setContentType("image/jpeg");
int len = 0;
byte[] b = new byte[1024];
while ((len = in.read(b)) != -1) {
os.write(b,0,len);
}
os.close();
in.close();
}
}catch(Exception e){
e.printStackTrace();
}finally{
dbSource.close();
}
%>
</body>
</html>
print.jsp// show.jsp與同一目錄
String zpPath = basePath+"show.jsp?xh=" + xh ;
"<td rowspan='4' ><img width=141 height=300 src="+ zpPath + "></td></tr>" +
==================================================
參考地址:
http://singlewolf.javaeye.com/blog/278769
====