0

尝试访问动态 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 休息服务类

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“localhost:8080/apps/inspiration.html”来访问 HTML 文件,这是当我右键单击 HTML 文件并在服务器上运行时 eclipse 给出的 url . 我正在使用 Tomcat v7.0.70

任何帮助将不胜感激!

4

1 回答 1

0

You don't seem to have anything written to serve static content. You'll need to do something like this.

于 2016-07-18T02:17:15.220 回答