简体   繁体   English

Eclipse Tomcat错误404

[英]Eclipse Tomcat Error 404

I am a newbee trying to learn JSF. 我是一个尝试学习JSF的新手。 Can you please help me with the error 404 in eclipse..! 您能帮我解决Eclipse中的错误404吗?! I tried changing the server details by going into Properties and still it give me the error. 我尝试通过进入“属性”来更改服务器详细信息,但仍然给我错误。

Please help me with this. 请帮我解决一下这个。 thanks in advance. 提前致谢。

my login code is as 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>

My loginbean file: 我的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 file: 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>

Assuming all dependencies are there and all other configurations you just need to add the following to your web.xml. 假设所有依赖项都存在,并且所有其他配置都只需将以下内容添加到web.xml中。 I also recommend you read the java ee 7 tutorials and use Netbeans since you are just beginning. 我还建议您阅读Java ee 7教程,并开始使用Netbeans。

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

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

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