【问题标题】:Jersey not loading index.html泽西岛没有加载 index.html
【发布时间】:2016-09-01 15:08:54
【问题描述】:

我在使用项目设置方式加载 index.html 时遇到了一些困难 - 我的结构如下所示;

我的 web.xml 如下所示;

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <module-name>restprj</module-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>SpringApplication</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.rest.test.demo.MyApplication</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringApplication</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>
</web-app>

我可以毫无问题地调用我的休息端点 - 例如

http://localhost:8080/service/entry-point/test2/hi

这给了我输出 - 但是如果我导航到 url http://localhost:8080/service/ 我得到一个 404 - 我将 index.html 放在哪里没有区别 - 有人能指出我做错了什么吗?

谢谢

【问题讨论】:

    标签: java html spring jersey


    【解决方案1】:

    您似乎将index.html 放在/target 文件夹中,请使用src/main/webapp 文件夹来存放您的所有.js.html 文件。每次您mvn clean install 时都会清理目标文件夹,并且它们永远不会包含在您的包装中。

    完成更改后,构建项目,将 war 复制到某个位置,将 .war 重命名为 .zip,提取内容并查看它是否包含根文件夹中的 index.html 文件。您可以在我建议的更改之前和之后执行此操作,以了解 index.html 的打包方式和位置。

    【讨论】:

    猜你喜欢
    • 2020-03-22
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多