JSF h标签没有显示

时间:2012-08-03 03:19:58

标签: jsf facelets

使用Netbeans在Glassfish 3.1.2.2上部署Web应用程序,并且我的h标签都不会显示在Web上。例如:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
    <head>
        <title>Draft Savvy Beers</title>
    </head>
    <h:form>
        <h:body>
            <h1>Search for beers</h1>
            <p><strong>Would you like to search for a beer?</strong>
                <h:inputText value="#{draftSavvyController.searchTerm}" />
                <h:commandButton value="#{draftSavvyController.searchforBeers}" /></p>
        </h:body>
    </h:form>
</html>

仅显示文本,不显示输入字段或按钮。使用普通的旧HTML显然会显示字段和按钮,但我无法以这种方式访问​​我的控制器。这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
    <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>
    <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>login.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

如果我能提供更多信息,请告诉我。我对此很陌生......

1 个答案:

答案 0 :(得分:7)

将此添加到您的web.xml

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

我认为问题的原因是请求没有通过FacesServlet传递。

页面网址与FacesServlet的网址格式不匹配,因此没有机会解析标记。