备用:
struts.xml代码:
<action name="getDocumentImg" class="JcOffDocumentAction" method="getDocumentImg"><!-- 获取文档图片流 -->
<result type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
</result>
</action>
action类代码:
/**
* 获取图片流
* @return
*/
public String getDocumentImg() {
model = (JcOffDocument)baseBO.load(model);
String imgUrl = getAllPath(model);
//String imgUrl = "/jczfoa/images/aa.jpg";
if(!MyUtils.isFileExist(imgUrl, "")){//如果指定的图片不存在,显示默认图片
imgUrl = getSession().getServletContext().getRealPath("/")+"images"+File.separator+"zw.jpg";
}
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream input = new BufferedInputStream(new FileInputStream(imgUrl));
byte[] bt = new byte[1024];
while (input.read(bt) > 0) {
bos.write(bt);
}
this.inputStream = new ByteArrayInputStream(bos.toByteArray());
bos.close();
input.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
private ByteArrayInputStream inputStream;
public ByteArrayInputStream getInputStream() {
return inputStream;
}
public void setInputStream(ByteArrayInputStream inputStream) {
this.inputStream = inputStream;
}