8

I am throwing exception in a scenario. Which is handled by @ExceptionHandler. But when throwing exception it says Request method 'POST' not supported
Controller code

@RequestMapping(value = "abcd", method = {RequestMethod.POST,RequestMethod.GET })
public String testAbc(Model model, HttpServletRequest request) throws Exception {
    //some piece of code
    if(someCondition)
        throw new Exception("No data found with id ");
}

Code in ExceptionController class

@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("errorMessage", ex.getMessage());
    modelAndView.addObject("errorDetails", ExceptionUtils.getStackTrace(ex));
    modelAndView.setViewName("forward:errorPage");

    return modelAndView;
}

Have no idea what I am doing wrong.

sandy
  • 1,153
  • 7
  • 21
  • 39
  • what says this? your exceptionhandler? Could it just be that your first line throws this exception, and you are catching that, and your own exception doesn't really come in to play? – Nanne Dec 19 '12 at 08:59
  • No.There is some business logic in method and one condition should throw error Which is handled in ExceptionController having method handleException. – sandy Dec 19 '12 at 09:55

1 Answers1

5

It seems that the controller that handles /errorPage does not take request method POST. In your @ExceptionHandler method, you are doing a forward to that page by setting view name to forward:errorPage.

Can you confirm if errorPage controller does handle POST method.

Viral Patel
  • 8,506
  • 3
  • 32
  • 29
  • Can you post some code. How `errorPage` is mapped. Is there errorPage.jsp page and are you using `` tag? – Viral Patel Dec 19 '12 at 10:13
  • My bad.I thought forward:errorPage is for rendering relevant jsp.Though it was mapped to controller,which was not allowing POST request.Thanks. – sandy Dec 20 '12 at 10:39