jsp:
<img height="60" width="80" src="/downloadPic.do?id=33" />
struts配置:
<!-- 图片下载 -->
<action name="downloadPic" class="newsAction" method="downloadPic">
<result name="picResult" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
action:
// 获取图片的byte[]
ImageBean bean = this.newsService.downloadPic(id);
fileName = bean.getName();
// 将图片byte[]放入ByteArrayInputStream中
inputStream = new java.io.ByteArrayInputStream(bean.getImageContext());
// 返回struts中的名称
return "picResult";
<img height="60" width="80" src="/downloadPic.do?id=33" />
struts配置:
<!-- 图片下载 -->
<action name="downloadPic" class="newsAction" method="downloadPic">
<result name="picResult" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
action:
// 获取图片的byte[]
ImageBean bean = this.newsService.downloadPic(id);
fileName = bean.getName();
// 将图片byte[]放入ByteArrayInputStream中
inputStream = new java.io.ByteArrayInputStream(bean.getImageContext());
// 返回struts中的名称
return "picResult";