有时候咱们在页面中展现的图片是根据后台动态获取的,这样有两种方式能够得到图片数据库
一、咱们的服务器端存在图片服务器
二、图片以bolb的方式存储在服务器中的数据库中ide
对于第一种状况,咱们直接替换在前台的<img src=""/>scr标签的地址就行。this
第二种状况,咱们须要从后台获得图片流,以流的方式进行显示。咱们借用sturt2进行配置以下:图片
<img src="file_show.action">get
struts2中返回值要配置为stream类型,以下:input
<action name="file_*" method="{0}" class="xxxx"/>it
<result type="stream">
<param name="contentType">p_w_picpath/png</param>
<param name="inputName">inputStream</param>
</result>
io
</action>class
代码中以下
public String show(){
this.inputStream = agentPhoto.getBinaryStream();
return SUCCESS;
}
这样就实现了图片从后台流中获取数据了