gpt4 book ai didi

java - tomcat 在 html 中显示 404 错误,但 jsp 工作正常

转载 作者:行者123 更新时间:2023-11-28 22:33:45 25 4
gpt4 key购买 nike

我使用 Intellij IDEA 通过 tomcat 7.0.64 创建一个简单的 WebApplication。

然后我在 IDEA 中运行 tomcat http://localhost:8080/可以正常工作,显示 index.jsp。然后我可以附加 xxx.jsp 以转到该页面。但如果我想转到 .html 页面,则会出现 404 错误:404 error

如果我在浏览器中打开 .html 文件,它可以正常工作并显示内容。

在我更改了 index.jsp 的名称后(我猜 index.html 应该是门),问题仍然存在。

我的文件夹层次结构: project folders

编辑:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">


</web-app>

实际上什么都没有,因为项目什么都不生成,而且我不知道应该配置哪些属性。

最佳答案

一切都很简单,你可以通过添加这些标签在你的 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">
<display-name>name you want to see</display-name>
<welcome-file-list>
<welcome-file>html/index.html</welcome-file>
</welcome-file-list>
</web-app>

然后 index.html 将在运行您的应用程序时作为第一页加载

关于java - tomcat 在 html 中显示 404 错误,但 jsp 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38004751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com