response.sendredirect 无法在外部应用程序中工作

response.sendredirect not working in external application

当我从外部应用程序调用时,

Response.sendRedirect(URL) 不工作。我正在同时处理两个企业应用程序。

应用程序 A:http://localhost:9080/abc

应用程序 B:http://localhost:8080/xyz

Angular 正在从应用程序 B 检索响应的应用程序:http://localhost:9000

目前,我在 App-A 并正在 AJAX 呼叫 App-B。当服务命中 App-B RestController 时,我想从 App-B.

的 RestController 重定向到浏览器中的 http://localhost:9000

我在 App-B 的 RestController 中尝试了以下方法,但它不起作用。仍然,浏览器 URL 是 http://localhost:9080/abc 指向 App-A:

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Location", "http://localhost:9000");
    httpServletResponse.setStatus(302);
}

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public ModelAndView method() {
    return new ModelAndView("redirect:http://localhost:9000");
}

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.sendredirect("http://localhost:9000");
}

我需要在启动 angular 应用程序之前将数据从 App-A 传递到 App-B。所以,我正在从 App-A 拨打 AJAX 电话。我无法通过传递查询参数直接从 App-A 调用 Angular 应用程序。我必须通过 header 或请求 body 传递数据。 你能帮忙吗?

对 ajax 请求的重定向响应不会自动导致页面重定向。您需要在响应处理程序中手动触发重定向。

参见 Redirecting after Ajax post