【问题标题】:How to create JSF 2.0 project on Eclipse AND Websphere Community Edition 2.1如何在 Eclipse AND Websphere Community Edition 2.1 上创建 JSF 2.0 项目
【发布时间】:2011-06-04 10:03:25
【问题描述】:

我想在 Eclipse 3.6 中创建 JSF 2.0 项目,我想将它部署在 Websphere Application Server Community Edition 2.1 上。

我创建了一个简单的网络项目。

index.html我写了这段代码

<!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:f="http://java.sun.com/jsf/core"
 xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
 <title>JSF 2.0</title>
</h:head>
<h:body>
jsf welcome
</h:body>
</html>

&lt;h:body&gt;&lt;h:body&gt; 标签之间的文字在页面中看不到。我该如何解决这个问题?

这是构建路径:

这是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" id="WebApp_ID" version="2.5">
  <display-name>JSFApp</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>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
</web-app>

有什么错误吗?

【问题讨论】:

  • 尝试从项目设置中为 JSF 2.0 添加构面。如果没有其他可以为您添加有用的验证。
  • @erloewe:考虑到 Libraries 屏幕截图中的 JSF 条目和 web.xml 中的(糟糕的)Eclipse-default /faces/* url 模式,可能已经添加了构面。
  • @Balusc 这些东西是在我出现后添加到问题中的 :) 只是确保,只是确保......顺便说一句很好的答案。
  • @erloewe:抱歉,我现在看到了时间戳。谢谢你:)

标签: jsf-2 websphere eclipse-3.6


【解决方案1】:

有2个问题:

  1. 您使用的是.html,而不是.xhtml。 JSF 2.0 默认解析*.xhtml 上的视图。将您的 index.html 重命名为 index.xhtml

  2. 您应该通过与FacesServleturl-pattern 匹配的URL 在浏览器中打开页面,在您的情况下为/faces/*。因此:http://example.com/contextname/faces/index.xhtml 而不是http://example.com/contextname/index.xhtml,甚至不是 .html。

    但是,我建议您将/faces/* 替换为*.xhtml,这样您(和您的最终用户)在忽略或忘记URL 中的/faces 部分时不必感到惊讶。唯一的缺点是,如果没有FacesServlet 的参与,您将无法提供“普通香草”.xhtml 文件,但在现实世界中几乎不会出现这种情况。而是只提供.html 这样的文件。

另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 2016-06-09
    • 1970-01-01
    • 2023-01-18
    相关资源
    最近更新 更多