【问题标题】:Tomcat running but gives 404 when trying to access my html, but instead shows tomcat's default page after installationTomcat正在运行但在尝试访问我的html时给出404,但安装后显示tomcat的默认页面
【发布时间】:2018-10-21 05:57:25
【问题描述】:

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

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>

项目结构

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

【问题讨论】:

  • 由于我们无法访问您的本地主机,因此需要源代码。
  • 当然,我的错。刚刚更新以包含我的源代码。
  • 你是如何部署它的?确保您使用的上下文根与文件夹或文件名完全匹配。项目中的 context.xml 经常被忽略。
  • 我在netbeans中做了这个项目,context.xml是自动生成的。我也在通过 netbeans 部署它。
  • 当你说上下文根时,你是指context.html中的&lt;Context path="" /&gt;吗?

标签: java tomcat netbeans


【解决方案1】:

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

【讨论】:

  • 好吧,没关系,我实际上只是在他们的文档中找到了它的说明。
  • ... 或者您可以手动将您的 .war 文件复制到 Tomcat 的 webapps 目录,这将执行相同的操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-30
  • 1970-01-01
相关资源
最近更新 更多