首页 > 解决方案 > Tomcat正在运行但在尝试访问我的html时给出404,但安装后显示tomcat的默认页面

问题描述

我是 tomcat 的新手,我只是想制作一个 hello world 应用程序来习惯 tomcat,但是当我启动我的应用程序并转到http://localhost:8080/helloweb/index.html它给了我一个404 错误。如果我去http://localhost:8080/那么它会把我带到 tomcat 的默认网页。请帮忙,我一直在尝试永远调试它,但似乎找不到其他有这个问题的人。

索引.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>

名称处理程序.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;
    }
}

上下文.xml

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

响应.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>

项目结构

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

标签: javatomcatnetbeans

解决方案


好吧,我想通了。我不得不进入http://localhost:8080/manager/html并手动上传 .war 文件。如果我错了,请纠正我,但我无法在 tomcat 文档的任何地方找到它。


推荐阅读