2

我正在尝试运行一个非常基本的 JSF 页面。使用 Websphere 7.0 作为服务器,所以我试图坚持使用 JSF 1.2。浏览器没有呈现 html,我的意思是它只是显示所有 html 代码,包括 doctype 等。
我的第一个猜测可能是它没有通过 FacesServlet,但是当 url-pattern 不匹配时它找不到页面。是 JSF 版本问题吗?还有其他想法吗?谢谢各位

我在我的 lib 文件夹中包含了 jstl-api-1.2.jar 和 jstl-imp-1.2.jar。

我设置了以下 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">
  <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.application.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</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>
</web-app>

面孔-config.xml:

<?xml version="1.0"?>
<faces-config 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-facesconfig_1_2.xsd"
   version="1.2">
</faces-config>

index.jsp:

<% response.sendRedirect("page-a.jsf"); %>

以及 xhtml 文件的开头:

<!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">
4

1 回答 1

1

您似乎正在尝试将 JSF 1.2 与 Facelets 1.x 一起使用。这很好,但在faces-config.xml. 您应该在那里有以下条目:

<application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>    
</application>

请注意,您需要该jsf-facelets.jar文件。

另请注意,您实际上不需要在 webapp中提供JSTL ;WebSphere 7 作为一个成熟的 Java EE 5 应用服务器已经自己提供了它。我建议删除那些 JSTL JAR 文件,因为它可能与 WebSphere 提供的文件冲突。JSF 也已由 WebSphere 提供,但 Facelets 并不是自 Java EE 6 以来只是 Java EE 的一部分。

Given the lack of Facelets view handler, I wonder if you're reading the right Facelets tutorial (since JSF 2.0, a Facelets <view-handler> configuration is not mandatory as it's the default view handler already, so perhaps you were accidently reading a JSF 2.0 targeted tutorial, while you should really be reading the one for JSF 1.x), so for the sake of completeness, here's a link to the official developer guide of Facelets 1.x.

于 2012-12-21T04:16:30.747 回答