公司介绍 业务范围 软件开发 网站建设 域名报价 服务报价 域名注册 智能建站 合作代理 兼职 在线反馈 联系我们 最新消息 java 技术文章 其他文章 公司首页
 
从blob取得文件
发布日期:2002-12-10
package test;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;



public class Servlet1 extends HttpServlet {
    static final private String CONTENT_TYPE = "image/gif";

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        OutputStream out = response.getOutputStream();
        FileInputStream fis = new FileInputStream("c:aaa.gif");
        int b = fis.read();
        while(b!=-1){
            out.write(b);
            b = fis.read();

        }
        fis.close();
    }
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException {
        doGet(req,resp);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException {
        doGet(req,resp);
    }
}

////////////////////////////////////////////////////////////////////

//JSP

<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>Jsp1</title>
</head>
<body>
<img border="0" src="servlet1">

</body>
</html>


先取出:ResultSet.getBytes(int columnIndex)或者getBlob(String colName)
在用BufferedOutputStream(new FileOutputStream).write(byte[] b)写就可以了。

 

联系地址:东莞市旗峰路方中电脑城B606室 TEL:0769-22456114 FAX:0769-86222884
网站地图 友情连接 联系我们