无法从jetty访问index.html

时间:2016-12-14 20:04:14

标签: java jetty web.xml

我正在尝试部署jetty服务器。部署正在进行,我可以访问所有资源。但是我无法访问web根目录中的文件,特别是index.html。以下是我的配置:

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--REST SERVLET-->
    <!--This need to add so that spring is called before jersey-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--This need to add so that jersey knows where is spring config-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/conf/my_spring/spring*.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <!-- Register resources and providers under com.altinn.rest package. -->
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>
                com.altin.api;com.fasterxml.jackson.jaxrs.json
            </param-value>
        </init-param>
        <init-param>
            <!--http://howtodoinjava.com/jersey/jersey-file-upload-example/-->
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

目录结构:

.
├── build.gradle
├── java-api.iml
├── resources
│   └── conf
│       └── my_spring
│           └── spring-config.xml
├── src
│   └── com
│       └── altin
│           └── api
│               └── base
│                   ├── AuthenticationFilter.java
│                   ├── PingRestAPI.java
│                   └── config
│                       └── spring
│                           └── ApiSpringConfig.java
└── web
    ├── WEB-INF
    │   └── web.xml
    └── index.html

提取的war看起来像:

$ tree -L 2
.
├── META-INF
│   └── MANIFEST.MF
├── WEB-INF
│   ├── classes
│   ├── lib
│   └── web.xml
└── index.html

application.wadl看起来像:

enter image description here

据我说,上下文路径是/因为我在intellij中将其标记为root,并且我能够访问ping上的/资源。

但我无法访问index.html

1 个答案:

答案 0 :(得分:2)

我遇到了这个问题。问题是

<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
web.xml中的

。该子句将所有请求转发给jersey servlet(ServletContainer)。我刚刚将规则更改为api/*index.html开始工作。