Struts2中,如果不需要保存文件,只为了图片显示,图片不需要下载,获取到文件流就可以了。
Struts.xml配置如下:
<result name="downloadProcessImage" type="stream">
<param name="inputName">inputStream</param>
<!-- name属性的值固定,为inputName,值inputStream与Javabean对应 -->
</result>
JBPM获取流的代码:
action:
public String downloadProcessImage(){
InputStream inputStream = elecProcessDefinitionService.downloadProcessImageById(elecProcessDefinition);//elecProcessDefinition是根据模型驱动获取到的对象。
elecProcessDefinition.setInputStream(inputStream);
return "downloadProcessImage";
}
获取到流之后,只需要再把对象放入到栈顶即可。
service:
public InputStream downloadProcessImageById(
ElecProcessDefinition elecProcessDefinition) {
String id = elecProcessDefinition.getId();
try {
id = new String(id.getBytes("gbk"),"UTF-8");//对从客户端获取到的中文进行转码
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ProcessDefinition processDefinition = processEngine
.getRepositoryService().createProcessDefinitionQuery()
.processDefinitionId(id).uniqueResult();
String deploymentId = processDefinition.getDeploymentId();
String resourceName = processDefinition.getImageResourceName();
InputStream inputStream = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName);
return inputStream;
}
jsp:
<a href="#" οnclick="openWindow('${pageContext.request.contextPath }/system/elecProcessDefinitionAction_downloadProcessImage.action?id=<s:property value="%{#pd.id}"/>','700','400');">