繁体   English   中英

Helloworld JSF2.0页面未呈现为html标签

[英]Helloworld JSF2.0 Page is not rendering as html tags

我是Java和JSF的新手。 我正在使用Eclipse Indigo和Tomcat 6.0.3和JSF 2.0。

当我在浏览器中运行Page时,我只会得到一个空页面,但是我可以将Firebug中的元素仍保留在JSF标签本身中。 它不在html中呈现。

这是我的web.xml

 <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>/app/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>pages/AddUser.xhtml</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>

我试图将url-pattern添加为*.xhtml但仍然无法正常工作。

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

<h:head>
        <title>Add New User Form</title>
</h:head>
    <h:body>
        <f:view>
             <h:form>
                     <h:outputText value="Age"></h:outputText>
                 </h:form>
            </f.view>
      </h:body>

问题在于JSF servlet的模式是<url-pattern>/app/*</url-pattern> 将模式更改为*.jsf并访问http://localhost:8080/yourXhtmlFileName.jsf

尝试localhost:8080 / app / ContactFormJSF。 它取决于您在web.xml中配置的<url-pattern> 您的URL应该与模式匹配,以便Faces Servlet可以处理您的请求并呈现页面。

WEB-INF/lib文件夹下的库可能会丢失。

在大多数情况下,所需的jar无法正确配置

  • 确保您的罐子在WEB-INF/lib目录下

您是否在web.xml文件中使用了以下标记?

<welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>//you are missing "faces"
</welcome-file-list>

完整的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>
    <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/pages/index.xhtml</welcome-file>
</welcome-file-list>

更新

元素类型f:view必须以匹配的结束标记</f:view>终止。

   <f:view>
         <h:form>
                 <h:outputText value="Age"></h:outputText>
         </h:form>
   </f.view>   //Here it should be </f:view>

您正在使用. 您应该使用: 以下是更正的格式:

   <f:view>
         <h:form>
                 <h:outputText value="Age"></h:outputText>
         </h:form>
   </f:view>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM