Search code examples
jspspring-rest

How To Serve Spring-Rest Response To JSP View


Hi, I don't know this right question or not but i got doubt thats why i posted this question.

if i use @RestController then i can write my response directly to HTTP Response object. But, i want to serve that response to JSP. how to serve this response to JSP? please , help me on this, i searched and read so many blogs and websites still i didn't get any clarification. #inSTACKOVERFLOW How to use Spring 4 Rest Controller to serve for Jsp view? I got this one, but here Same question asked by some one, here they are suggested like instead of @RestController use @Controller for JSP View.

@Controller: This Annotation introduced in Spring2.5 Version. For Supporting WEB-Services, the spring people used @ResponseBody with @Controller , if You Use @ResponseBody Then you can write response directly into Http Response. Later

@RestController: This Annotation introduced in Spring4.0 Version, Instead of using @Controller+@ResponseBody simple you can use @RestController.

so, finally with help of @RestController we can write response directly into HTTP Response Object. This Response, i want to send to JSP View.

i know, by using ajax we can do it. but if i use ajax i can get every response into same page only.

Here , if i want to use JSP's for View with the combination of Spring-Rest, how can i pass my response to jsp view.

Please help me.


Solution

  • Make it the way as Quissal said.

    With a rest controller, your return type is normaly some kind of object for serialisation (like into json) and NOT a jsp page

    To do a web application you have to use @controller and a jsp mapping.

    There a lot of examples on the web, like: http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example-annotation/