日期:2014-05-17  浏览次数:20732 次

BufferedImage对象怎么在jsp页面中使用img标签显示
在一个jsp页面中获取到一个BufferedImage的对象,我本是将该对象以文件的形式保存到服务器上的,现在想直接以流的形式显示在页面中。
附以文件的形式保存到服务器的代码。
try {    
    byte[] bytes1 = (byte[])list.get(i).get("userHeadPhoto");        
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);    
    BufferedImage bi1 =ImageIO.read(bais);    
    File w2 = new File(src+"webapps/dat/user/temp/"+list.get(i).get("userId")+".jpg");
    ImageIO.write(bi1, "jpg", w2);
} catch (IOException e) {    
    e.printStackTrace();    
}   %>
<img src="/data/user/temp/<%=list.get(i).get("userId")%>.jpg" style="margin-bottom: 5px;width: 60px;height: 60px;"/>



------解决方案--------------------
src="/data/user/temp/<%=list.get(i).get("userId")%>.jpg"

你这个是从服务器的更路径下获取data....?

加上这里句试试<%=path %>其中path是eclipse新建jsp页面默认在head上面申明的一变量,如果没有就用request.getContextPath()代替。
------解决方案--------------------
<img src="**.jsp?id=***" style="margin-bottom: 5px;width: 60px;height: 60px;"/>

然后在jsp中获取id,并把BufferedImage写入response的outputstream就行了。
------解决方案--------------------
引用:
Quote: 引用:

<img src="**.jsp?id=***" style="margin-bottom: 5px;width: 60px;height: 60px;"/>

然后在jsp中获取id,并把BufferedImage写入response的outputstream就行了。

BufferedImage怎么写入response的outputdtream?


使用javax.imageio.ImageIO.write就可以了。