I have the following controller, xx-servlet.xml file. But resolver.resolveException is returning null. I don't why?
<b>Here's the part of xxx-servlet.xml that has exceptionMapping</b>
<b>Here's the controller</b>Code:<bean id="exceptionMapping" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="mappedHandlers"> <set> <ref bean="loginController" /> </set> </property> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">genericErrorView</prop> </props> </property> </bean>
NOTE: Intentionally I tried to add something to hashtable without instantiating it. So, a Null Pointer Exception must be thrown. Actually in the controller, if I remove try catch then at runtime when the controller is executed it does redirect me to the error page I have configured. but, the moment i add try-catch and call resolver.resolveMethod(), ModelAndView is returned null. I don't why?Code:public class LoginController extends SimpleFormController { private SimpleMappingExceptionResolver resolver; public LoginController() { setCommandClass(LoginDetails.class); setCommandName("loginDetails"); resolver = new SimpleMappingExceptionResolver(); } protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors) throws Exception { ModelAndView mv = null; try { LoginDetails ld = (LoginDetails)command; String clientId = "a1"; Hashtable h = null; h.put("Hello","hello"); mv = new ModelAndView(new RedirectView("CustomerOptions.htm")); //mv.addObject("errors",errors.getModel()); return mv; } catch(Exception e) { mv = resolver.resolveException(request,response,"loginController",e); System.out.println("mv " + mv); return mv; } }


Reply With Quote