怎么把数据库(db2)中blob字段(图片)读出,并显示到jsp中?(来者有分)

beien9 2003-11-11 02:35:58
在severlt中怎么读出?
读出后怎么传送到jsp中?
jsp中怎么显示?

最好给个serverlt的例子, 和jsp显示图片的例子!

gutu@sina.com

以前的帖子就是取出blob, 怎么在jsp中显示啊?
分++
...全文
102 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
beien9 2003-11-14
  • 打赏
  • 举报
回复
终于搞定。
Rabbit8 2003-11-12
  • 打赏
  • 举报
回复
GZ
beien9 2003-11-12
  • 打赏
  • 举报
回复
我要例子啊。 顺便up
gyscsdn 2003-11-12
  • 打赏
  • 举报
回复
jsp页面中加入<IMG height=99 src="servlet名称?id=<%=rs.getInt("id")%>" width=136></td>
如上面的servlet名称:DownLoad
9731boy 2003-11-11
  • 打赏
  • 举报
回复
呵.我一般都不会存入数据库.不方便.数据量一大就很讨厌了
XSimple 2003-11-11
  • 打赏
  • 举报
回复
我也试一试,谢谢你们!
beien9 2003-11-11
  • 打赏
  • 举报
回复
大侠们帮忙
springouting 2003-11-11
  • 打赏
  • 举报
回复
学习
beien9 2003-11-11
  • 打赏
  • 举报
回复
ServletOutputStream op = response.getOutputStream();
后怎么在我的mapid.jsp显示这个图片啊?
luckybeggar 2003-11-11
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
(转)这是调用servlet的



在页面上你这样调用<src="DownLoad?id=">

就可以了



import java.sql.*;

import java.io.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;









public class DownLoad extends HttpServlet{

public DownLoad() {

}

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request,response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

System.out.println("======DownLoad begin=====");

try{

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.216.0.2:1521:ORCL","dms","dms");

Statement stmt=conn.createStatement();

String id=request.getParameter("id");

String sql="SELECT id, name, content FROM zyw_test where id='"+id+"'";

ResultSet rs=stmt.executeQuery(sql);

if(rs.next()){

Blob blob = rs.getBlob("content");

byte[] ab = blob.getBytes(1, (int)blob.length());

response.setContentType("image/jpeg");

ServletOutputStream op = response.getOutputStream();

op.write(ab);

op.flush();

op.close();

}

}catch(Exception ex){

ex.printStackTrace();

}

System.out.println("======DownLoad end=====");

}

}


beien9 2003-11-11
  • 打赏
  • 举报
回复
kongxiangli(笑看红尘) 能不能说清楚一点?
或连接的url?
zwxu 2003-11-11
  • 打赏
  • 举报
回复
读取blob类型的具体代码自己写吧,不难,转到jsp页面可以在servlet中把图片对象放到request中,再从jsp中读出来
凋零的老树 2003-11-11
  • 打赏
  • 举报
回复
网易论坛的精华区
webchoirsql 2003-11-11
  • 打赏
  • 举报
回复
不会,支持。
jintaocom 2003-11-11
  • 打赏
  • 举报
回复
一心学习中!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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