In my application I have configured an error page in web.xml. I need to override that for a specific controller based on a condition. Here when a condition becomes true I need to redirect to a specific error page otherwise normal error page should be rendered.
Here is the code. Please help me.
@Controller
public class Test{
@ExceptionHandler(Exception.class)
public ModelAndView generateException(HttpServletRequest httpServletRequest){
if(condition) {
return new ModelAndView("myError.jsp");
} else {
//should execute default error page.
}
}
}
Throw the exception again which will be handled by DefaultHandlerExceptionResolver to respond with the error page defined in your web.xml; It doesn’t invoke the same Exception Handler of the controller.