练笔做商城,需要从数据库中查询图片组(好多图片),二进制流,然后展示到界面上。
目前不知道该怎么实现,下面是我的代码,但是展示不出来。
action:
List prods = product.queryProductbyCatalog(catalogId);
Map parameters = null;
ByteArrayInputStream bais = null;
if(null!=prods && prods.size()>0){
for (int i = 0; i < prods.size(); i++) {
bais = new ByteArrayInputStream(prods.get(i).getPic());
BufferedImage bi1 =ImageIO.read(bais);
File w2 = new File("d:\1.jpg");
ImageIO.write(bi1, "jpg", w2);
prods.get(i).setShowPic(w2);
productsList.add(prods.get(i));
}
}
struts2 图片展示 不出来
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2016-07-26 16:37关注
你把图片写入文件了,没有传回客户端
参考这个例子
http://blog.csdn.net/closewbq/article/details/5761888注意
HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("image/gif"); int size=in.available(); byte[] image=new byte[size]; in.read(image); ServletOutputStream out=response.getOutputStream(); out.write(image);
这里的代码才是写回给客户端
解决 无用评论 打赏 举报