Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t在我的jsf2应用程序中显示pdf文件_Pdf_Jsf 2_Primefaces - Fatal编程技术网

Can';t在我的jsf2应用程序中显示pdf文件

Can';t在我的jsf2应用程序中显示pdf文件,pdf,jsf-2,primefaces,Pdf,Jsf 2,Primefaces,我试图在我的jsf2应用程序上显示一个pdf文件,但问题出在路径文件中 我的pdf文件位于名为FichesPratiques的文件夹中,该文件夹位于另一个名为resources的文件夹中(文件夹resources位于WebContent中),我使用该文件夹来显示它: <p:media value="/resources/FichesPratiques/file.pdf" width="100%" height="300px"> 但任何东西都会显示出来 更奇怪的是,当我使用下面的

我试图在我的jsf2应用程序上显示一个pdf文件,但问题出在路径文件中

我的pdf文件位于名为FichesPratiques的文件夹中,该文件夹位于另一个名为resources的文件夹中(文件夹resources位于WebContent中),我使用该文件夹来显示它:

<p:media value="/resources/FichesPratiques/file.pdf" width="100%" height="300px">

但任何东西都会显示出来

更奇怪的是,当我使用下面的链接下载它时,它不起作用

<h:outputLink value="/resources/FichesPratiques/file.pdf">click</h:outputLink> to download pdf instead.
点击下载pdf。

有人能帮我吗?

仔细查看这些组件的HTML输出中生成的URL(右键单击,在webbrowser中查看源代码)。与
等不同的是,
没有在URL中预先设置web应用程序上下文路径。URL中的前导
/
使其相对于请求URL的域根(如浏览器地址栏中所示)

假设JSF页面是由

http://localhost:8080/somecontext/page.xhtml

然后那些
value=“/resources/FichesPratiques/file.pdf”
路径将期望资源出现在

http://localhost:8080/resources/FichesPratiques/file.pdf

然而,你实际上有它

http://localhost:8080/somecontext/resources/FichesPratiques/file.pdf

您应该使用相对于当前请求URL的有效URL

<p:media value="resources/FichesPratiques/file.pdf" ... />

或者在URL中显式指定上下文路径

<p:media value="#{request.contextPath}/resources/FichesPratiques/file.pdf" ... />