在JSF頁面中顯示數(shù)據(jù)庫的圖片

          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{
          // 準(zhǔn)備語句執(zhí)行對(duì)象
          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兩個(gè)頁面在同意目錄中的,在完成以上兩個(gè)頁面后就可以進(jìn)行測(cè)試了
          在ie中輸入http://localhost:8089/...../list.faces查看效果。

          posted on 2008-09-19 14:51 魯勝迪 閱讀(1826) 評(píng)論(0)  編輯  收藏 所屬分類: 一點(diǎn)點(diǎn)

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          新聞分類

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 延津县| 保德县| 南康市| 文化| 广宗县| 屯门区| 靖边县| 柳林县| 尉氏县| 白银市| 新干县| 汝南县| 德阳市| 高碑店市| 东港市| 宝山区| 土默特左旗| 大姚县| 玛纳斯县| 满洲里市| 泽库县| 秭归县| 五寨县| 绿春县| 英山县| 阿拉善盟| 措美县| 望奎县| 金沙县| 灵宝市| 巴马| 利辛县| 稷山县| 沙坪坝区| 临沂市| 壤塘县| 平安县| 怀柔区| 井冈山市| 阳西县| 名山县|