我需要在我的球衣网络服务中重定向到特定的外部网址
我正在使用这种方法:
public static Response redirectTo(String path) {
URI uri;
try {
uri = new URI(path);
return Response.seeOther(uri).build();
} catch (URISyntaxException e) {
e.printStackTrace();
return null;
}
}
但它导航到白屏页面而不是stackoverflow.com.
为什么会发生这种情况以及如何解决?
在此方法中调用此方法
@GET
@Path("/login")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response login(@Context UriInfo info, @Context HttpServletRequest request) {
...
String url = "https://stackoverflow.com";
redirectTo(url);
}
从AppDirect触发事件时(通过浏览器)调用login方法的url
最佳答案 我最终将@Context HttpServletResponse res参数添加到我的方法并调用此方法res.sendRedirect(urlApp);
这是按预期工作的.