how to use spring4 @RestController to return a jsp page?

You shouldn't. A @RestController is not meant to return view names through a String return type/value. It's meant to return something that will be written to the response body directly.

More concretely (in the general configuration case), Spring MVC configures its return value handlers in RequestMappingHandlerAdapter#getDefaultReturnValueHandlers(). If you look at that implementation, the handler for String view names, ViewNameMethodReturnValueHandler, is registered after the handler for @RestController (really @ResponseBody), RequestResponseBodyMethodProcessor.

If you really have to, you can declare your method to have a return type of View or ModelAndView (the handlers for these, ViewMethodReturnValueHandler and ModelAndViewMethodReturnValueHandler, are registered before RequestResponseBodyMethodProcessor) and return the appropriate object, with an identifying view name.


Actually, a @RestController can also return view:

  1. Set the controller method's return type to be ModelAndView

  2. Set your view path like this:

    ModelAndView mav = new ModelAndView("userCenter/loginPage");

  3. return mav;

You get the correct JSO page view content.