Bên trong phương thức REST REST Tôi muốn chuyển tiếp đến một trang web khác. Làm thế nào tôi có thể đạt được điều đó?Chuyển tiếp URL Jersey
@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:
Tôi nhận được lỗi No thread local value in scope for proxy of class $Proxy78
khi cố gắng để làm một cái gì đó như thế này:
@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
@Context
ServletContext context;
...
RequestDispatcher dispatcher = context.getRequestDispatcher("url");
dispatcher.forward(request, response);
Tôi quan tâm đến chuyển tiếp, không chuyển hướng. –
@DorinGrecu chỉ cần thêm cách truy cập vào ngữ cảnh – Dewfy
@Derwy Vui lòng xem câu hỏi đã chỉnh sửa của tôi, nó không hoạt động ngay lập tức. –