Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC @RestController and redirect

I have a REST endpoint implemented with Spring MVC @RestController. Sometime, depends on input parameters in my controller I need to send http redirect on client.

Is it possible with Spring MVC @RestController and if so, could you please show an example ?

like image 663
alexanoid Avatar asked Mar 16 '15 19:03

alexanoid


1 Answers

Add an HttpServletResponse parameter to your Handler Method then call response.sendRedirect("some-url");

Something like:

@RestController public class FooController {    @RequestMapping("/foo")   void handleFoo(HttpServletResponse response) throws IOException {     response.sendRedirect("some-url");   }  } 
like image 158
Neil McGuigan Avatar answered Sep 26 '22 13:09

Neil McGuigan