在JSF頁面中顯示數據庫的圖片

          list.jsp用于顯示圖片的JSF頁面
           <h:graphicImage url="show.jsp"/>
            
          show.jsp 用于獲取圖片信息的jsp頁面
          <%@ page contentType="text/html; charset=gbk" %>
          <%@ page import="java.io.*"%>
          <%@ page import="java.sql.*, javax.sql.*" %>
          <%@ page import="java.util.*"%>
          <%@ page import="java.math.*"%>

          <%
          //String photo_no = request.getParameter("photo_no");

          //mysql連接 
          //Class.forName("com.mysql.jdbc.Driver").newInstance();
          //String URL="jdbc:mysql://localhost:3306/job?user=root&password=111111";
          //Connection con = DriverManager.getConnection(URL);

          //oracle連接 jdbc:oracle:thin:@192.168.1.33:1521:ora9i
          String URL="jdbc:oracle:thin:@192.168.1.33:1521:ora9i";
          String user
          ="wtcx";
          String password
          ="wtcx";
          Connection con 
          = DriverManager.getConnection(URL,user,password);


          try{
          // 準備語句執行對象
          Statement stmt = con.createStatement();

          String sql 
          = "select t.* from t_file t Where fileid Like '402881e41c460e0a011c460eccd50009' ";
          ResultSet rs 
          = stmt.executeQuery(sql);
          if (rs.next()) {
          Blob blob 
          = rs.getBlob("content");
          long size = blob.length();
          //out.print(size);
          byte[] bytes = blob.getBytes(1, (int)size);
          response.setContentType(
          "image/jpeg"); 
          OutputStream outs 
          = response.getOutputStream(); 
          outs.write(bytes);
          outs.flush();
          rs.close(); 
          }

          else {
          rs.close();
          response.sendRedirect(
          "./images/error.gif");
          }

          }

          finally{
          con.close();
          }

          %>
           list.jsp和show.jsp兩個頁面在同意目錄中的,在完成以上兩個頁面后就可以進行測試了
          在ie中輸入http://localhost:8089/...../list.faces查看效果。

          posted on 2008-09-19 14:51 魯勝迪 閱讀(1825) 評論(0)  編輯  收藏 所屬分類: 一點點

          <2008年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導航

          統計

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          新聞分類

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 始兴县| 金门县| 姚安县| 扶沟县| 凤冈县| 弥勒县| 海南省| 遂川县| 宽甸| 永寿县| 敦化市| 台湾省| 留坝县| 清涧县| 隆子县| 古交市| 新沂市| 喀喇沁旗| 建宁县| 东阳市| 房产| 错那县| 岳阳市| 抚远县| 扶风县| 安溪县| 呈贡县| 内黄县| 洛隆县| 琼海市| 博乐市| 惠东县| 嘉义市| 长寿区| 台安县| 荣成市| 上思县| 神木县| 昌都县| 吉木乃县| 昌黎县|