PrimeFaces fileDownload does not work

后端 未结 4 1318
深忆病人
深忆病人 2021-01-02 18:03

I can\'t get the primeFaces work. While I succeed in downloading the file using a custom download bean. Seems like the issu is related to the

4条回答
  •  醉酒成梦
    2021-01-02 18:07

    InputStream stream = this.getClass().getResourceAsStream("sessionlog.csv");
    

    The way as you have located the CSV file expects it to be in the same package as the current class, the FileDownloadBean.

    If it is actually located in the package root, then you should rather be using:

    InputStream stream = this.getClass().getResourceAsStream("/sessionlog.csv");
    

    Or if it is actually located in a different package, for example com.example, then you should rather be using:

    InputStream stream = this.getClass().getResourceAsStream("/com/example/sessionlog.csv");
    

    Or if it is actually located in the root of the public webcontent (there where the /WEB-INF folder also is, among all other web files), then you should rather be using:

    InputStream stream = externalContext.getResourceAsStream("/sessionlog.csv");
    

    (which by the way also works fine for the WAR classes instead of this.getClass())

提交回复
热议问题