我正在创建一个Java REST Web服务。由于某种原因,启动页面index.jsp给了我一个HTTP状态404 - 未找到错误。我的index.jsp在web文件夹中。我的web.xml包含
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
它还包含
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
我注意到当我删除servlet映射时索引页面正常工作。但我需要那个映射。我一直在阅读类似的帖子,但找不到我的问题的答案。非常感谢任何帮助。谢谢。
答案 0 :(得分:2)
制作你的web.xml文件
这件事:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
比此行包含您的项目名称
<display-name>Project name</display-name>
这是您欢迎的文件列表
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
Servlet映射
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
这里需要在servlet映射中删除* 更改您的映射代码
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/Jersey</url-pattern>
答案 1 :(得分:1)
初始页面应始终为index.html而不是index.jsp。另外,用index.html替换index.jsp所需的引用。它会工作。加载index.html页面后,您可以将其重定向到您喜欢的任何页面。 Glassfish或Tomcat服务器总是查找并首先加载它。