gpt4 book ai didi

jsp - 如何从 JAX-RS 服务转发到 JSP?

转载 作者:可可西里 更新时间:2023-11-01 15:12:45 24 4
gpt4 key购买 nike

JBoss 版本:4.2.3GA。这适用于 apache tomcat 6.0。在 JBoss 中,我必须添加以下设置:-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=false 才能让转发工作,但现在当我加载页面时,出现以下错误。感觉我正在以一种 JBoss 不喜欢的方式来做这件事,但我还没有看到任何其他例子。有谁知道如何让它发挥作用?

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

...


@GET
@Path("/forward")
public String forward(
@Context final HttpServletRequest request,
@Context final HttpServletResponse response) throws Exception
{
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.html");
dispatcher.forward(request, response);
return "";
}

异常:

java.lang.ClassCastException: $Proxy114 cannot be cast to javax.servlet.ServletRequestWrapper
com.itt.scout.server.servlet.admin.config.ConfigController.forward(ConfigController.java:46)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:151)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

最佳答案

在从其他地方获得一些帮助后,我意识到我正在以一种有趣的方式连接我的 JSP 和 reSTLet,而我真正想做的是使用一个 Viewable。这在 JBoss 中也能更好地工作。以下是我最终的总结:

import javax.ws.rs.core.Context;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import com.sun.jersey.api.view.Viewable;


@GET
@Path("/index")
public Viewable index(
@Context HttpServletRequest request,
@Context HttpServletResponse response) throws Exception
{
request.setAttribute("key", "value");
return new Viewable("/jsps/someJsp.jsp", null);
}

关于jsp - 如何从 JAX-RS 服务转发到 JSP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6984338/

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