|
 |
|
| 从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)写就可以了。
|
|
| |
|
|
|
|
|