Alv*_*Sim 5 java jsf primefaces
在我的maven项目中,我创建了一个"index.xhtml"文件.当我构建并运行项目时,Web浏览器没有显示任何内容.当我查看源代码时,我仍然可以看到源代码,而不是普通的html标记.
我试过通过以下方式创建XHTML文件:
上述方法均无效.
Maven POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProfitV10</groupId>
<artifactId>ProfitV10</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProfitV10</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3.1</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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)
的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:spinner />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是第一种情况.第二种情况,我已经有了一个运行PrimeFaces的NetBeans Web应用程序项目."index.html"确实呈现了.但是当我创建一个新的JSF页面并包含PrimeFaces名称空间时xmlns:p="http://primefaces.org/ui",但是这个特殊的JSF和其他新创建的JSF页面将不会呈现.
一定是我想念的东西,但我不知道是什么.
我的环境如下:
谢谢.
由于您使用的/index.xhtml是欢迎文件,因此您还应该将FacesServlet映射到该扩展名.
如果您不需要现有的前缀映射,请将其替换为:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
否则只需添加*.xhtml模式意味着您将最终得到:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
请注意,您几乎总是希望在*.xhtml那里进行映射,以防止将Facelets的源代码暴露给公众.
更新:
关于.jsf和.xhtml之间的区别:
.jsf是默认映射之一(如果你没有在JSF 2.1中声明FacesServlet,你会得到这个).它源于磁盘上物理文件的扩展名(.jsp或.xhtml)与URL中使用的扩展名之间的差异.
不幸的是,这些在历史上是不同的,因为JSF是一种附加技术,必须通过一个单独的显式Servlet(Faces Servlet).纯JSP从来没有这个限制,因为它更多的内置.JSF页面最初只在JSP中创作,因此如果您在URL请求中使用了.jsp,则容器将直接转到JSP并跳过Faces Servlet.
因此,必须为此发明一种解决方法,即将Faces Servlet映射到*.jsf,然后Faces Servlet将指向JSP文件,该文件仍然.jsp在磁盘上具有扩展名.
我个人认为简单*.xhtml的*.xhtml映射是唯一理智的开箱即用选项,但由于向后兼容性,似乎JSF不能再将其设置为默认值.
| 归档时间: |
|
| 查看次数: |
10297 次 |
| 最近记录: |