Java 使用spring控制器重定向到外部链接
我遇到过这样一个案例,我不得不从一个特定的控制器重定向一个指向外部url的链接Java 使用spring控制器重定向到外部链接,java,spring,http,jakarta-ee,Java,Spring,Http,Jakarta Ee,我遇到过这样一个案例,我不得不从一个特定的控制器重定向一个指向外部url的链接 response.sendRedirect(url_location); 我也试过类似的东西 response.setHeader("location",url_location); 尝试将返回类型作为Model和View发送。但是没有效果。有人能帮我解决吗?我看到很多人建议使用sendRedirect和setHeader方法,但在我的情况下不起作用。因此我也想知道是否有任何配置可用于使用这些HttpServeR
response.sendRedirect(url_location);
我也试过类似的东西
response.setHeader("location",url_location);
尝试将返回类型作为Model和View发送。但是没有效果。有人能帮我解决吗?我看到很多人建议使用sendRedirect和setHeader方法,但在我的情况下不起作用。因此我也想知道是否有任何配置可用于使用这些HttpServeResponse方法。您可以尝试一下
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("redirect:" + redirectUrl);
}
或者
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
httpServletResponse.setHeader("Location", redirectUrl);
}
试一试
return new ModelAndView("redirect:" + url_location);
或
通过response.sendRedirect(url\u位置)可以得到什么;这和
return "redirect:" + url_location;
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("redirect:" + projectUrl);
}