gpt4 book ai didi

java - 当我的 HTML 文件位于 WebContent 文件夹中时,为什么在 Tomcat 7.0.70 上会出现错误 404(请求的资源不可用。)?

转载 作者:行者123 更新时间:2023-11-28 23:25:00 24 4
gpt4 key购买 nike

尝试访问我的动态 Web 项目中的 HTML 文件时,我不断收到错误 404。

这是我的 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/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>NMWebServices</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>
</welcome-file-list>
<servlet>
<servlet-name>NMServlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.nilaymodi.services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>NMServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

我的 html 文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Inspiration Generator</title>
</head>
<body>
<p>testing</p>
</body>
</html>

我的java rest服务类

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/inspiration")
public class Endpoints {

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getInspiration() {
Inspiration inspiration = InspirationFactory.generate();

Gson gson = new Gson();
String result = gson.toJson(inspiration, Inspiration.class);

return Response.ok(result, MediaType.APPLICATION_JSON).build();
}

@GET
@Path("/test")
@Produces(MediaType.TEXT_PLAIN)
public Response testConnection() {
return Response.ok("Sucess! Service is running.", MediaType.TEXT_PLAIN).build();
}
}

在 url "localhost:8080/apps/inspiration/"上完全正常工作

我的上下文根是“apps”,我试图用 url 访问 HTML 文件“localhost:8080/apps/inspiration.html”,当我右键单击 HTML 文件并转到在服务器上运行时,eclipse 给出的 url。我正在使用 Tomcat v7.0.70

如有任何帮助,我们将不胜感激!

最佳答案

您似乎没有编写任何内容来提供静态内容。你需要做 something like this .

关于java - 当我的 HTML 文件位于 WebContent 文件夹中时,为什么在 Tomcat 7.0.70 上会出现错误 404(请求的资源不可用。)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427419/

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