简体   繁体   中英

Tomcat running but gives 404 when trying to access my html, but instead shows tomcat's default page after installation

I'm new to tomcat, I'm just trying to make a hello world application to get used to tomcat, but when I start my application and go to http://localhost:8080/helloweb/index.html it gives me a 404 error. If I go to http://localhost:8080/ then it takes me to the default webpage for tomcat. Please help, I've been trying to debug this forever but can't seem to find anyone else that is having this problem.

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Index Page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <h1>Entry Form</h1>

        <form name="Name Input Form" action="response.jsp">
            Enter your name:
            <input type="text" name="Name" value="" />
            <input type="submit" value="OK" />
        </form>
    </body>
</html>

NameHandler.java

package org.mypackage.hello;

public class NameHandler {
    private String name;

    public NameHandler() { 
        name = null;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
}

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/helloweb"/>

response.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <jsp:useBean id="mybean" scope="session" class="org.mypackage.hello.NameHandler" />
        <jsp:setProperty name="mybean" property="name" />
        <h1>Hello, <jsp:getProperty name="mybean" property="name" />!</h1>
    </body>
</html>

Project Structure

My_Project_Root
 |-- pom.xml
 |-- nb-configuration.xml
 `-- src
     `-- main
         |-- java
         |   `-- com
         |       `-- example
         |           `-- my_project
         |               `-- sample_class.java
         |-- resources
         `-- webapp
             |-- META-INF
                 `-- context.xml
             |-- WEB-INF
             |-- index.html

Okay, I figured it out. I had to go into http://localhost:8080/manager/html and manually upload the .war file. Please correct me if I'm wrong, but I was unable to find this anywhere in tomcat's documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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