国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

從數據庫讀出的JPG文件的字符流,轉換成圖片顯示在頁面上的相關代碼

2019-11-18 16:34:45
字體:
來源:轉載
供稿:網友

public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    ServletOutputStream out = res.getOutputStream();
    Statement dispStmt = null, setStmt = null;
    try {
        dispStmt = Con.createStatement();
        setStmt = Con.createStatement();
        setStmt.executeUpdate("set textsize 2048000");
    } catch (Exception e) {
        out.    }

    String ls_sql = null;
    ls_sql = req.getParameter("ImageSQL");
    if (ls_sql == null)
        ls_sql = "";
    ls_sql = ls_sql.trim();
    if (!ls_sql.equals("")) {
        ResultSet rs = null;
        try {
            rs = dispStmt.executeQuery(ls_sql);
        } catch (Exception e) {
            System.out.println(
                "Unable to Exec Statment" + e.toString() + "<br>");
        }
        try {
            while (rs.next()) {
                try {
                    res.setContentType("image/jpeg");
                    InputStream is = rs.getBinaryStream(1);
                    int size = is.available();
                    byte[] bzp = new byte[size];
                    is.read(bzp);
                    out.write(bzp);
                } catch (Exception e) {
                    System.out.println("Wirte image error: " + e.toString());
                }
            }
            rs.close();
        } catch (Exception e) {
            System.out.println("Unable to Close Statment" + e.toString());
        }
    }
    try {
        dispStmt.close();
    } catch (Exception e) {
        System.out.println("Close Statement Error: " + e.toString());
    }
    out.close();
}

--------------------------------------------------------------------------------

再附一個:

從庫中讀圖片顯示到頁面上的主要源碼
 <%@ page contentType="text/html;charset=iso8859_1"%>
<%@ page import="java.sql.ResultSet"%>
<jsp:useBean id="query" class="pub.MakeDB"/>
<%
String sql = "select * from images";
ResultSet rs = query.executeQuery(sql);
rs.next();
InputStream in = rs.getBinaryStream("image");
ServletOutputStream sos = response.getOutputStream();
int len = 0;
byte[] b = new byte[1024];
response.reset();
response.setContentType("image/gif");
while((len = in.read(b)) > 0)
sos.write(b,0,len);
in.close();
sos.close();
query.cls();
%>
如果是寫到文件只要把sos
定義為DataOutputStream sos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("/a.gif")));


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新田县| 芜湖市| 剑阁县| 依安县| 江津市| 潞西市| 理塘县| 本溪| 弥渡县| 夹江县| 定兴县| 武川县| 泸州市| 温州市| 富顺县| 大荔县| 深泽县| 榆树市| 芮城县| 穆棱市| 阿克苏市| 彰武县| 东丰县| 嘉黎县| 兴国县| 和田县| 瑞金市| 衡南县| 蓝山县| 射洪县| 拉萨市| 榆树市| 屯留县| 阳泉市| 榆社县| 蓝田县| 湘潭县| 淮阳县| 镇宁| 石首市| 张北县|