jsf2 xhtml页面不被浏览器解释

use*_*704 4 jsf-2

我正在测试coreservlets网站上的应用程序"jsf-blank",以便了解jsf如何工作,但我的浏览器没有显示xhtml页面的内容.

我使用Tomcat 6和Eclipse Indigo.

你知道为什么我的浏览器中的页面是空白的吗?

谢谢您的帮助.

谢谢,但它不适用于jsp指令,这是我的web.xml的内容:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

最后更新 :

我尝试了你的解决方案,但我有同样的问题,jsf标签不是由浏览器呈现(我是JSF的新手).

我的测试非常简单:

web.xml:

<?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"                             xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<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>
</servlet>
<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>
Run Code Online (Sandbox Code Playgroud)

index.xhtml:

  <!DOCTYPE html>
  <html lang="en"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:ui="http://java.sun.com/jsf/facelets">
     <h:head>
       <title><h:outputText value="First JSF Application" /></title>
     </h:head>
     <h:body>
        <h:outputText value="Test" /> 
     </h:body>
   </html>
Run Code Online (Sandbox Code Playgroud)

上下文名称:jsf-blank

我用url测试:http:// localhost:8080/jsf-blank/index.xhtml

结果:空白页面

最后更新 :

谢谢,我的问题解决了,我认为问题的根源是我的tomcat文件夹shared/lib中的rich-faces 3.3 jars.

我删除了这些罐子,现在它正在工作,你知道为什么这是一个问题吗?

Bal*_*usC 5

当您发送了一个URL与URL模式不匹配的请求时,就会发生这种情况,FacesServlet这反过来导致JSF的工作根本不会运行.根据servlet映射的URL模式,您必须请求.jsf扩展的XHTML页面.想象一下,你有一个index.xhtml,然后你需要通过http:// localhost:8080/contextname/index.jsf来调用它.

但是,我建议只更换*.jsfURL模式,*.xhtml这样您就不必担心和混淆后缀.改变你的web.xml如下:

<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>
</servlet>
<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>
Run Code Online (Sandbox Code Playgroud)

并通过http:// localhost:8080/contextname/index.xhtml打开页面.