I am using spring mvc 4 for a web application and i wanted to know that if a post request is made in angular js to the controller can we use request dispatcher in the same controller to forward request and response to another page because currently I am not able to forward the request and response to another jsp page .Is there any other alternative to do server side redirection when using angular js where i can forward my request and response objects to another jsp page.
Is there any way to forward a request object to angular js along with a json object basically a method to forward the parameter values of request object to angular js?
It is possible to redirect in Spring using UriComponentsBuilder Class.
@RequestMapping(value="/RequestMappingUrl", method = RequestMethod.POST)
public ResponseEntity<> redirectExample(){
HttpHeaders headers = new HttpHeaders();
UriComponentsBuilder b = UriComponentsBuilder.fromPath("/redirectURL");
UriComponents uriComponents = b.build();
return new ResponseEntity<void>(headers,HttpStatus.FOUND);
}
In AngularJS, ng-route can be used to display the template corresponding to the url. Otherwise, you can determine which page to display from Spring MVC Controller.
@RequestMapping(value="/redirectURL",method = RequestMethod.GET)
public String getFaultAndRejectedMessagesPage() {
return "htmlPageToDisplay";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With