使用<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
提交
取消
