我的 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">
<display-name>restapp</display-name>
<distributable/>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的主要 Application 类看起来像这样:
package com.example.restapp;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class RestApplication extends Application {}
我的目录结构是这样的:
- src/main/webapp
- /字体
- /图片
- /WEB-INF
- index.jsp
- index-qa.jsp
- 样式表.css
我的 jax-rs rest 应用端点已从 http://localhost:8080/restapp/api/test
成功提供服务
我的 index.jsp 已从 http://localhost:8080/restapp/index.jsp
成功提供
然而,当在 http://localhost:8080/restapp/
上执行 GET 时,Tomcat 返回 404。
虽然我可以通过一些 URL 重写等方法来解决这个问题,但我知道 Tomcat 支持这个并且只是想了解为什么这不起作用。我已经尝试了添加 servlet
和 servlet-mapping
标签等任意数量的组合,但都放弃了,现在我只是在寻找为什么它被破坏了以及我能做些什么来解决这个问题。 Java 服务器今天不是我的 friend 。
最佳答案
根据Apache Tomcat 8 Configuration Reference ,您必须遵循 war
文件命名约定:
关于java - <welcome-file-list> 在 Tomcat 中被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54643549/