java web二进制流的图片如何用response返回给前台

boss_2012 2014-08-06 01:53:59
代码片段:
InputStream in = connection.getInputStream();
GZIPInputStream gzin = new GZIPInputStream(in);
FileOutputStream file = new FileOutputStream(new File("F:\\123.gif"));
byte[] bytes = new byte[1024*1024];
int length = 0;
while((length=gzin.read(bytes))!=-1){
file.write(bytes,0,length);
}
file.write(bytes, 0, length);
file.close();
in.close();



以上代码写在servlet层,实现了把一个图片的流拿到,并且写入一个文件中,
现在要实现的是:
把这个图片流用servlet的response直接返回到前台页面,通过解析在前台JSP页面上把这个图片显示出来
请教如何去做
...全文
6639 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
业余草 2014-08-06
  • 打赏
  • 举报
回复
OutputStream out = this.getResponse().getOutputStream();
			out.write(这里写内容);
			out.flush();
			out.close();

10,612

社区成员

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

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