在Jersey REST方法中,我想转发到另一个网站。我怎样才能做到这一点?Jersey URL转发
@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 "";
}
}
编辑:
试图做这样的事情的时候,我发现了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);
我对转发感兴趣,而不是重定向。 –
@DorinGrecu只是添加如何去上下文 – Dewfy
@Derwy请看我编辑的问题,它不会马上工作。 –