【问题标题】:jsf2 xhtml pages not interpreted by browser [duplicate]jsf2 xhtml页面不被浏览器解释[重复]
【发布时间】:2011-12-13 05:56:18
【问题描述】:

我正在从 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>

最后更新:

我尝试了你的解决方案,但我遇到了同样的问题,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>

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>

上下文名称:jsf-blank

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

结果:空白页

最后更新:

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

我删除了这些罐子,现在它可以工作了,你知道为什么会出现问题吗?

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    当您发送的请求的 URL 与 FacesServlet 的 URL 模式不匹配时,可能会发生这种情况,这反过来会导致 JSF 工作根本无法运行。根据您的 servlet 映射的 URL 模式,您必须请求带有 .jsf 扩展名的 XHTML 页面。假设您有一个index.xhtml,那么您需要通过http://localhost:8080/contextname/index.jsf 调用它。

    不过,我建议将*.jsf URL 模式替换为*.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>
    

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

    【讨论】:

      【解决方案2】:

      基本上,只要配置文件或其他任何内容出现任何错误,MyFaces 的 JSF 2 实现就会返回空白页。更糟糕的是,错误也没有发送到日志中。改用 Mojarra(Oracle 的 JSF 2 实现),您将开始收到清晰的错误消息。

      【讨论】:

        【解决方案3】:

        RichFaces 在 web.xml(RichFaces 过滤器等)中有自己的配置,所以如果您不想使用它,您应该删除该库,因为您没有为其应用任何合适的配置,以便正确触发。

        【讨论】:

          猜你喜欢
          • 2012-11-17
          • 2015-11-25
          • 1970-01-01
          • 2016-10-09
          • 1970-01-01
          • 1970-01-01
          • 2015-05-21
          • 1970-01-01
          • 2011-04-22
          相关资源
          最近更新 更多