gpt4 book ai didi

java - 无法从jetty访问index.html

转载 作者:行者123 更新时间:2023-12-02 03:10:23 25 4
gpt4 key购买 nike

我正在尝试部署 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 的根目录,而且我还可以访问 ping资源 / .

但我无法访问index.html :

最佳答案

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

<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

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

关于java - 无法从jetty访问index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41151249/

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