1.基于XML配置
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!--跳转为fail.html-->
<prop key="java.lang.ArithmeticException">fail</prop>
</props>
</property>
<!--异常ex值为e.getMessage会放入请求域中-->
<property name="exceptionAttribute" value="ex"></property>
</bean>
2.基于代码
@ExceptionHandler({ArithmeticException.class,NullPointerException.class})
public String handlerEx(Exception ex,Model model){
model.addAttribute("ex",ex);
return "fail";
}