Announcement Announcement Module
Collapse
No announcement yet.
Using @ExceptionHandler to return a Html View for Json request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using @ExceptionHandler to return a Html View for Json request

    Hi,

    I am using Spring Rest to process JSON request and return a JSON response, all works fine.

    Now i want to return a html view to user in case JSON request processing throws an exception. For this i have used @ExceptionHandler to create a ModelAndView, but after returning the response DispatcherServlet uses MappingJacksonView to render the response.

    Is there a way i can render a HTML Page( in case of error) for request with accept header as application/json

    @ExceptionHanlder(value=MultipleItemsFoundExceptio n.class
    public ModelAndView handleMultipleItemError(MultipleItemsFoundExceptio n e, HttpServletResponse response){
    ModelAndView mav = new ModelAndView();
    mav.setViewName("detail");
    mav.addObject("list",e.getItemList());
    response.setContentType("text/html");
    return mav;
    }
    Last edited by jany2k; Sep 22nd, 2010, 04:05 PM.
Working...
X