gpt4 book ai didi

jsf-2 - 如何在 JSF 2.0 中制作下载文件?

转载 作者:行者123 更新时间:2023-12-04 06:06:15 25 4
gpt4 key购买 nike

我在 WebContent/WEB-INF/resources/file/theFile.pdf 中有文件定位,我可以知道当用户单击页面链接时如何下载将显示常规下载弹出对话框或在网页中呈现它的文件(只要最简单的方法都可以)?我正在使用 JSF2.0,目前正在使用 h:outputLink下载 pdf 文件但没有运气,控制台输出显示此错误:

File not found: /pages/resources/file/theFile.pdf

如何告诉 JSF 删除 /pages并以 /resources 开头因为我的文件位于资源文件夹中。

这是下载代码:
<h:outputLink value="resources/file/theFile.pdf">
<h:graphicImage library="images" name="pdf.jpg" style="border:none"/>
</h:outputLink>

最佳答案

I have file locate inside WebContent/WEB-INF/resources/file/theFile.pdf



首先是 /WEB-INF的内容(和 /META-INF )是 不是 公开可用(因为它们可能包含敏感信息,例如 web.xml、标签文件、模板等)。将文件放在 /WEB-INF 之外的公共(public)网络内容中.

假设它现在位于 WebContent/resources/file/theFile.pdf ,然后您可以按如下方式链接到它:
<h:outputLink value="#{request.contextPath}/resources/file/theFile.pdf">
<h:graphicImage library="images" name="pdf.jpg" style="border:none"/>
</h:outputLink>

无关 对于具体问题,您对 library 的使用 <h:graphicImage> 上的属性没有意义。另见 What is the JSF resource library for and how should it be used?

关于jsf-2 - 如何在 JSF 2.0 中制作下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com