我将 jersey 2.4 用于我的 Web 服务,并且无法让主页加载 index.jsp。我也做了一个 IndexService POJO 来尝试从那里加载它,但这不起作用。我想只使用主页,而不是使用 IndexService POJO。到达 POJO 但返回:
HTTP 状态 500 - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:找不到媒体类型 = 文本/html、类型 = 类 org.glassfish.jersey.server.mvc.Viewable、通用类型 = 类 org.glassfish.jersey 的 MessageBodyWriter .server.mvc.Viewable。
我的 web.xml 文件:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>rest</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
<param-value>/WEB-INF/jsp/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
依赖 pom.xml 文件:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
<dependencies>
索引服务 POJO:
@Path("/")
public class IndexService {
@GET
@Path("/index")
@Produces(MediaType.TEXT_HTML)
public Viewable indexPage() {
return new Viewable("/index.jsp", null);
}
}