使用<h:GraphicImage>或<img>标记从webapp/webtext/Deploy我需要使用JSF显示Web应用程序中部署文件夹之外的图像<h:graphicimage>标记或HTML<img>标签。我怎样才能做到这一点?
3 回答
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
<h:graphicImage><img>
<Context path="/myapp" aliases="/images=/path/to/external/images"></Context>
<h:graphicImage<img>
<h:graphicImage value="/images/my-image.png">
<img src="/myapp/images/my-image.png">
<p:fileDownload>
<h:form>
<h:commandLink id="downloadLink" value="Download">
<p:fileDownload value="#{fileDownloader.getStream(file.path)}" /> </h:commandLink></h:form@ManagedBean@ApplicationScopepublic class FileDownloader {
public StreamedContent getStream(String absPath) throws Exception {
FileInputStream fis = new FileInputStream(absPath);
BufferedInputStream bis = new BufferedInputStream(fis);
StreamedContent content = new DefaultStreamedContent(bis);
return content;
}
}}
阿晨1998
TA贡献2037条经验 获得超6个赞
private StreamedContent image;public void setImage(StreamedContent image) {
this.image = image;}public StreamedContent getImage() throws Exception {
return image;}public void prepImage() throws Exception {File file = new File("/path/to/your/image.png");
InputStream input = new FileInputStream(file);ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setImage(new DefaultStreamedContent(input,externalContext.getMimeType(file.getName()), file.getName()));}<body onload="#{yourBean.prepImage()}"></body> <p:graphicImage value="#{youyBean.image}" style="width:100%;height:100%" cache="false" >
</p:graphicImage>添加回答
举报
0/150
提交
取消
