着急ing!!请大侠指教!!!Jsp显示blob图片的问题。多谢多谢

jilongge 2003-05-09 10:35:23
下面的程序总不能成功!!!请指点!!多谢

ShowPhoto.jsp:
<%@ page import="java.sql.* " %>
<%@ page import="java.io.* " %>
<%
String driver = "COM.ibm.db2.jdbc.net.DB2Driver";
String url = "jdbc:db2://" + host + "/" + DBName;
try{
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, userID, passwd);
st = conn.createStatement();

String query = "select photo from info where id = 5";
ResultSet result = st.executeQuery(query);
result.next();


response.setContentType("image/jpeg");
Blob blob = (Blob)result.getBlob("photo");
int len = blob.length();
byte[] data = blob.getBytes(1,len);

ServletOutputStream sos = response.getOutputStream() ;
sos.write(data) ;
sos.close();
conn.close();
}catch(Exception e){ e.printStackTrace();}
%>

Test.jsp:
<html>
<h1>this is a test .</h1>
<img src="ShowPhoto.jsp">
</html>


...全文
89 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongqh21 2003-05-10
  • 打赏
  • 举报
回复
up
wafd 2003-05-10
  • 打赏
  • 举报
回复
好文
xywl 2003-05-10
  • 打赏
  • 举报
回复
使得ie的缓存信息,及时更新
enhydra1234 2003-05-09
  • 打赏
  • 举报
回复
不能直接这样sos.write(data) ;
要用bufferReader。
zez 2003-05-09
  • 打赏
  • 举报
回复
用楼上的方法,再加上这两句试试 .具体意义我也不太清楚
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);
leshui 2003-05-09
  • 打赏
  • 举报
回复
//取得数据库中的数据
Sql="select * from marklist order by markdate desc";
result=DbaObj.ExecuteQuery(Sql);
result.next();
//将数据库中的数据读到流中
InputStream in =result.getBinaryStream("markbody");
//设置输出的格式
response.reset();
response.setContentType("image/jpeg");
//循环去出流中的数据
byte[] b = new byte[1024];
int len;
while((len=in.read(b)) >0)
response.getOutputStream().write(b,0,len);
in.close();

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧