我是JSF的新手并且开始探索它并且我使用jsf创建了一个简单的登录应用程序,当我尝试通过apache tomcat服务器运行它时,它在浏览器中显示正常但问题是当我给出时凭据并尝试登录它显示页面的正确内容,但URL是这样的 JSF_Sample_2 / faces / Login.jsp,它必须是 JSF_Sample_2 / faces / Success.jsp,同时显示它只显示应用程序名称,如JSF_Sample_2 /
我的 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>JSF_Sample_2</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>
<welcome-file-list>
<welcome-file>faces/Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的 faces-config.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<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"> <managed-bean>
<managed-bean-name>loginFormBean</managed-bean-name>
<managed-bean-class>
com.Lawrence.JSF.LoginFormBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/Login.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/Success.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>Failure</from-outcome>
<to-view-id>/Failure.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/Login.jsp</to-view-id>
</navigation-case>
</navigation-rule> </faces-config>
我的托管Bean 是
package com.Lawrence.JSF;
public class LoginFormBean
{
private String userName;
private String passWord;
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getPassWord()
{
return passWord;
}
public void setPassWord(String passWord)
{
this.passWord = passWord;
}
public String doLogin()
{
if(getUserName().equals("Lawrence") && getPassWord().equals("lawrence"))
{
return "success";
}
else
{
return "Failure";
}
}
public String logOut()
{
return "home";
}
}
在成功页面以及失败页面我正在使用commandlink,其中action为loginformbean.logOut,它返回到登录页面,但也无效,我在faces-config规则中编写了导航规则 请帮我解决这个问题