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

时间:2016-06-24 02:30:02

标签: java html jsp tomcat intellij-idea

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

我在IDEA运行tomcat然后http://localhost:8080/工作正常,显示index.jsp.And然后我可以附加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>

实际上没有任何内容因为项目没有生成任何东西,我不知道应该配置什么属性。

3 个答案:

答案 0 :(得分:0)

一切都很简单,您可以通过添加这些标记

在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作为第一页加载

答案 1 :(得分:0)

我猜你已经将项目存储在正确的位置,并且端口8080是Tomcat运行服务器的地方。假设您有调用index.html的方式,Tomcat会在其默认文件夹中查找名为index.html的文件。它没有查找该文件的子目录。您可以看到原因,因为如果您有多个项目并且每个项目都有自己的index.html,那么它就不知道要显示哪个项目。

您需要告诉您的浏览器要查看哪个文件夹/项目。如果您的项目是“MyProject”,请在浏览器中输入 localhost:8080 / MyProject / index.html

基本上,您已经创建了一个本地服务器,并且您正在查看服务器所拥有的文件。它与您尝试通过终端查看文件时的情况相同。您正在为浏览器提供该文件的路径,因此您需要指定项目/文件夹名称。

答案 2 :(得分:-1)

您的路径可能不正确或您的tomcat盗版。嗯,也许前者更有可能。