在 Jersey REST 方法中,我想转发到另一个网站。我怎样才能做到这一点?
@Path("/")
public class News {
@GET
@Produces(MediaType.TEXT_HTML)
@Path("go/{news_id}")
public String getForwardNews(
@PathParam("news_id") String id) throws Exception {
//how can I make here a forward to "http://somesite.com/news/id" (not redirect)?
return "";
}
}
EDIT:
我得到了No thread local value in scope for proxy of class $Proxy78
尝试执行类似操作时出错:
@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
@Context
ServletContext context;
...
RequestDispatcher dispatcher = context.getRequestDispatcher("url");
dispatcher.forward(request, response);
public Response foo()
{
URI uri = UriBuilder.fromUri(<ur url> ).build();
return Response.seeOther( uri ).build();
}
我在我的应用程序中使用了上面的代码并且它有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)