JDBC讀取Oracle LONG RAW類型字段 顯示圖片

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

 

 

 

 

 

 

 

 

====

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章