请教,关于用servlet输出图象的问题。

winespirit 2004-09-06 04:55:38
1、我用servlet输出图象,采用jpeg格式,在页面用<img src="/icon.bmp">调用。我的开发环境是wsad 5。0。在windows的测试环境下通过,但是打包然后在aix上面在websphere中发布之后,图片显示不出来,这是为什么?
2、上面的问题有人说是由于图片格式的问题,这样我就想以bmp的格式输出,在servlet中我用的是BufferedImage来操作图片的,但是不知道该怎么才能输出到页面上面去,请教,急!
原来的jpg格式时候的输出部分程序如下:

import com.sun.image.codec.jpeg.*;
BufferedImage image = 。。。;
ServletOutputStream output = response.getOutputStream();

JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(output);
encoder.encode(image);

output.close();
...全文
163 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lishujin1981 2004-09-07
  • 打赏
  • 举报
回复
学习
Yujlyjl 2004-09-07
  • 打赏
  • 举报
回复
学习中
winespirit 2004-09-07
  • 打赏
  • 举报
回复
这些都是我用过的技术,那如何从BufferedImage中取得byte列表?
reack 2004-09-06
  • 打赏
  • 举报
回复
//读取数据库blob字段
sql="select blob_column from UTL_LOB_TEST where rownum=1";
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery(sql);

Blob blob = null;
byte[] bytes = null;
if(rs.next())
{
try{
oracle.sql.BLOB pic = (oracle.sql.BLOB)rs.getBlob("blob_column");
//设定输出格式
response.setContentType("images/jpeg");
//将blob对象转换为输入流
InputStream stream = pic.getBinaryStream();
//定义输出流
OutputStream os = response.getOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[8192];
//开始输出
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}

os.close();
stream.close();
}
catch(Exception e){
System.out.print(e.toString());
}
}
rs.close();
schwarzenegger 2004-09-06
  • 打赏
  • 举报
回复
http://www-900.ibm.com/developerWorks/cn/java/l-imgtxt/index.shtml

81,122

社区成员

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

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