无法使用Jersey服务器加载JSP页面 [英] Cannot have JSP page load with Jersey server
问题描述
我正在将jersey 2.4用于我的Web服务,并且无法让主页加载index.jsp.我制作了一个IndexService POJO来尝试从那里也加载它,但这是行不通的.我只想使用主页,而不要使用IndexService POJO.已达到POJO,但返回以下内容:
I am using jersey 2.4 for my web service and cannot have the home page load the index.jsp. I made a IndexService POJO to try loading it from there too, but that doesn't work. I would like to just use the home page, instead of the having an IndexService POJO. The POJO is reached but returns this:
HTTP状态500-org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:找不到针对媒体type = text/html,type = class org.glassfish.jersey.server.mvc.Viewable,genericType = class org的MessageBodyWriter. glassfish.jersey.server.mvc.Viewable.
HTTP Status 500 - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class org.glassfish.jersey.server.mvc.Viewable, genericType=class org.glassfish.jersey.server.mvc.Viewable.
我的web.xml文件:
My web.xml file:
<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 pom.xml files:
<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>
IndexService POJO:
IndexService POJO:
@Path("/")
public class IndexService {
@GET
@Path("/index")
@Produces(MediaType.TEXT_HTML)
public Viewable indexPage() {
return new Viewable("/index.jsp", null);
}
}
推荐答案
You need to add JspMvcFeature to the configuration of your application. Since you're using web.xml
to configure your application (package scanning of resources and providers, setting property) you need to add the following init-parameter
:
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.server.mvc.jsp.JspMvcFeature</param-value>
</init-param>
这篇关于无法使用Jersey服务器加载JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!