此代碼的工作對我來說:
import com.sun.jersey.api.view.Viewable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.MalformedURLException;
@Path("/test")
public class TestResource {
@GET
public Response getMessage(@Context final HttpServletRequest request,
@Context final HttpServletResponse response) throws MalformedURLException{
return Response.ok(new Viewable("/dummy.jsp")).type(MediaType.TEXT_HTML).build();
}
}
隨着src這內容/主/ web應用/ WEB-INF/JSP/dummy.jsp
Dummy response
的服務器是GlassFish 3.1.1 Jersey 1.17
也許是一個糟糕的web.xml配置或可視路徑? 我JSPTemplatesBasePath
<init-param>
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
<param-value>/WEB-INF/jsp</param-value>
</init-param>
[編輯] 我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.0">
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<filter>
<filter-name>jersey</filter-name>
<filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.ezakus.</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.ezakus.api.web.security.ResponseCorsFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
<param-value>/WEB-INF/jsp</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
<param-value>/(resources|js|css|img)/.*</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jersey</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/jsp/500.jsp</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/WEB-INF/jsp/503.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/jsp/404.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/WEB-INF/jsp/400.jsp</location>
</error-page>
</web-app>
在可視,你必須把路徑沒有你JSPTemplatesBasePath;)
我沒有在我的WEB.xml,所以我可以嘗試添加它。我會假設JSP在/WEB-INF/jsp/dummy.jsp?我正在使用WAS而不是Glassfish和Jersey 1.11(他們在回購中需要)因此,也許這兩個問題中的一個是問題。 – Jackie
也可以以某種方式鏈接到您的整個web.xml? – Jackie
正如我所提到的:src/main/webapp/WEB-INF/jsp/dummy.jsp –