0
我是一名試圖學習JSF的新手。你能幫我在日食中的錯誤404 ..! 我試圖通過進入屬性更改服務器的詳細信息,但它仍然給我錯誤。Eclipse Tomcat錯誤404
請幫我這個。提前致謝。
我登錄的代碼是folows:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head><title>JSF Login</title></head>
<body>
<h1>Login</h1>
<h:form>
<table>
<tr>
<td><h:outputText value="Username: " /></td>
<td><h:inputText id="loginname"
value="#{loginBean.uname}" />
</td>
</tr>
<tr>
<td><h:outputText value="Password: " /></td>
<td><h:inputSecret id="password"
value="#{loginBean.password}" />
</td>
</tr>
<tr>
<td> </td>
<td><h:commandButton value="Login"
action="#{loginBean.loginProject()}"/>
</td>
</tr>
</h:form>
</body>
</html>
我loginbean文件:
package beans;
import dao.UserDAO;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
@ManagedBean(name = "loginBean")
@SessionScoped
/**
*
* @author User
*/
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String password;
private String message, uname;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String loginProject() {
boolean result = UserDAO.login(uname, password);
if (result) {
// get Http Session and store username
HttpSession session = Util.getSession();
session.setAttribute("username", uname);
return "home";
} else {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Invalid Login!",
"Please Try Again!"));
// invalidate session, and redirect to other pages
//message = "Invalid Login. Please Try Again!";
return "login";
}
}
public String logout() {
HttpSession session = Util.getSession();
session.invalidate();
return "login";
}
}
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
謝謝,爲答覆..這對我有效。 – 2014-09-05 10:05:42
歡迎您,很高興它的工作。 – zulq 2014-09-05 10:55:51