我是 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>
名称处理器.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
最佳答案
好吧,我明白了。我不得不进入 http://localhost:8080/manager/html并手动上传 .war 文件。如果我错了,请纠正我,但我无法在 tomcat 的文档中的任何地方找到它。
关于java - Tomcat 运行但在尝试访问我的 html 时给出 404,但在安装后显示 tomcat 的默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281772/