亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用<h:GraphicImage>或<img>標記從webapp/webtext/Deploy

使用<h:GraphicImage>或<img>標記從webapp/webtext/Deploy

交互式愛情 2019-06-14 16:46:50
使用<h:GraphicImage>或<img>標記從webapp/webtext/Deploy我需要使用JSF顯示Web應用程序中部署文件夾之外的圖像<h:graphicimage>標記或HTML<img>標簽。我怎樣才能做到這一點?
查看完整描述

3 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

為了達到你所需要的<h:graphicImage><img>標簽,您需要創建一個Tomcatv 7別名,以便將外部路徑映射到Web應用程序的上下文中。

要做到這一點,您需要指定web應用程序的上下文..最簡單的方法是定義一個meta-INF/context.xml文件,其內容如下:

<Context path="/myapp" aliases="/images=/path/to/external/images"></Context>

然后,在重新啟動Tomcat服務器之后,可以使用<h:graphicImage>或<img>標簽如下:

<h:graphicImage value="/images/my-image.png">

<img src="/myapp/images/my-image.png">

*注意上下文路徑對于標記是必需的,但對于


如果不需要通過HTTPGET方法獲得映像,另一種可能的方法是使用PrimeFaces<p:fileDownload>標簽(使用命令鏈接命令按鈕標簽-http POST法).

在你的法布雷特:

<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;
       }
    }}


查看完整回答
反對 回復 2019-06-14
?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

在PrimeFaces中,您可以這樣實現bean:

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()));}

在HTML Faclet中:

<body onload="#{yourBean.prepImage()}"></body> <p:graphicImage value="#{youyBean.image}" style="width:100%;height:100%" cache="false" >
</p:graphicImage>

我建議在GraphicImage組件中設置屬性cache=“false”。


查看完整回答
反對 回復 2019-06-14
  • 3 回答
  • 0 關注
  • 1049 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號