泽西URL转发 [英] Jersey URL forwarding
本文介绍了泽西URL转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Jersey REST方法中,我想转发到另一个网站。我怎样才能实现呢?
Inside a Jersey REST method I would like to forward to an another website. How can I achieve that?
@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 "";
}
}
编辑:
我正在获取尝试执行此类操作时,类$ Proxy78
的代理范围内没有线程本地值这个:
I'm getting the No thread local value in scope for proxy of class $Proxy78
error when trying to do something like this:
@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();
}
我在我的应用程序中使用了上面的代码并且它有效。
I used above code in my application and it works.
这篇关于泽西URL转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文