JSF表单未显示

时间:2013-06-08 12:54:14

标签: jsf jsf-2

我想使用jsf实现我想要的登录页面 实现一个表单:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Login</title>
    <link href="../resources/css/basic.css" type="text/css" rel="stylesheet" />
</h:head>
<h:body>
<div id="wrapper">
    <ul id="menu">
        <li id="menutab"><a class="link" href="../index.jsp">Home</a></li>
        <li id="menutab"><a class="link" href="../jsf/list.jspx">Liste</a></li>
        <li id="menutab"><a class="link" href="../servlets/DataServlet">Daten</a></li>
        <li id="menutab"><a class="link" href="../servlets/ListMoviesServlet">Movies</a></li>
        <li id="menutab"><a class="link" href="../servlets/ListPeopleServlet">People</a></li>
    </ul>
    <br></br>
    <h2 id="title">Login</h2>

    <h:form id="j_security_check">
        <center>
            <h:messages errorClass="errorMessage" infoClass="infoMessage" warnClass="warnMessage"></h:messages>
            <h:panelGrid columns="2">
                <h:outputText value="Username : "/>
                <h:inputText id="j_username" value="#{loginBean.username}"/>

                <h:outputText value="Password : "/>
                <h:inputSecret id="j_password" value="#{loginBean.password}"/>

                <h:commandButton value="Submit" action="#{loginBean.login}" type="submit"/>
            </h:panelGrid>
        </center>
    </h:form>
</div>
</h:body>
</html>

显示页面但未显示此处定义的表单。一切 标题后只是一个白色的屏幕。 为什么表格没有呈现?

1 个答案:

答案 0 :(得分:0)

好的,我明白了!

这是我的web.xml中的jsf映射:

<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>
</servlet>

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

如您所见url-pattern描述“.jspx”

所以我必须用“myjsf.jspx”而不是“myjsf.xhtml”来调用我的jsf

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>loginRealm</realm-name>
    <form-login-config>
        <form-login-page>/jsf/login.jspx</form-login-page>
        <form-error-page>/jsf/error.jspx</form-error-page>
    </form-login-config>
</login-config>