0

Response.sendRedirect(URL) is NOT working when I call from an external application. I am working on two enterprise applications parallelly.

Application A: http://localhost:9080/abc

Application B: http://localhost:8080/xyz

Angular App which is retrieving response from Application B: http://localhost:9000

Currently, I am in App-A and making AJAX call to App-B. When service hit to App-B RestController, then I want to redirect to http://localhost:9000 in browser from RestController of App-B.

I tried the below approach in RestController of App-B, but it doesn't work. Still, browser URL is http://localhost:9080/abc which is point to 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");
}

I need to pass data from App-A to App-B before I launch angular application. So, I am making AJAX call from App-A. I can not directly call to Angular app from App-A with passing query param. I have to pass data through the header or request body. Could you help with this?

1 Answers1

0

A redirection response to an ajax request does not automatically cause a page to redirect. You need to manually fire the redirect in your response handler.

See Redirecting after Ajax post.

Deadron
  • 5,135
  • 1
  • 16
  • 27