spring.xml
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!-- exceptionMappings:配置哪些異常去哪些頁面 -->
<property name="exceptionMappings">
<props>
<!-- key:異常全類名儒飒;value:要去的頁面視圖名; -->
<prop key="java.lang.NullPointerException">myerror</prop>
</props>
</property>
<!--指定錯誤信息取出時使用的key -->
<property name="exceptionAttribute" value="ex"></property>
</bean>
ExceptionTestController.java
@RequestMapping("/handle04")
public String handle04(){
System.out.println("handle04");
String str = null;
System.out.println(str.charAt(0));
return "success";
}