Results 1 to 1 of 1

Thread: Using @ExceptionHandler to return a Html View for Json request

  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Lightbulb 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 at 04:05 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •