繁体   English   中英

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

[英]Why do I get an Error 404 (The requested resource is not available.) on Tomcat 7.0.70 when my HTML file is in the WebContent folder?

尝试访问动态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();
    }
}

在网址“ localhost:8080 / apps / inspiration /”下可以正常使用

我的上下文根是“ apps”,我试图用URL“ localhost:8080 / apps / inspiration.html”打HTML文件,这是当我右键单击HTML文件并在服务器上运行时eclipse提供的URL 。 我正在使用Tomcat v7.0.70

任何帮助将不胜感激!

您似乎没有编写任何内容来提供静态内容。 您需要执行以下操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM