<p:graphicImage src找不到404

时间:2019-06-22 18:17:24

标签: eclipse maven jsf primefaces jsf-2

我正在尝试读取项目中插入的一些图像,但是我做不到。 我创建了一个maven Dynamic Web Module 3.0项目,并在Web内容中插入了resources / images文件夹。我将文件夹添加到了构建路径中,因为我认为它无法访问,但无法正常工作。

我尝试了不同的代码模式:

<p:graphicImage value="resources/images/chardonnay.png"/>
<p:graphicImage value="#{resource['images/muller.png']} />
<p:graphicImage value="#{resources['images:muller.png']} />
<p:graphicImage library="images" name="riesiling.png"/>

这是我项目的结构

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>safetyfood</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet- 
class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>    

</web-app>

这是pom.xml

<properties>
<project.build.sourceEncoding>UTF- 
8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>

<!-- Prime faces dependency -->
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>6.2</version>
</dependency>


<!-- jsf maven dependency -->
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.2.14</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.2.14</version>
</dependency>

</dependencies>

<repositories>
<repository>
    <id>prime-repo</id>
    <name>PrimeFaces Maven Repository</name>
    <url>http://repository.primefaces.org</url>
    <layout>default</layout>
</repository>
</repositories>
</project>

控制台中的错误:

GET http://localhost:8080/safetyfood/resources/images/chardonnay.png? 
pfdrid_c=true 404
(index):25 GET http://localhost:8080/safetyfood/RES_NOT_FOUND 
404

1 个答案:

答案 0 :(得分:0)

已解决。

在web.xml中

<context-param>
    <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
    <param-value>/WEB-INF/resources</param-value>
</context-param>