SpringMVC异常处理

1.通过配置

   <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
             <property name="exceptionMappings">
                  <props>
                      <prop key="java.lang.RuntimeException">redirect:/error.jsp</prop>
                  </props>
             </property>
     </bean>

2、在controller中添加异常处理handler

@ExceptionHandler(RuntimeException.class)
    public String exception(RuntimeException ex){
        return "redirect:/error.jsp";
    }

 

posted @ 2015-11-13 23:46  常平  阅读(142)  评论(0编辑  收藏  举报