静态资源和异常处理

静态资源引用

<mvc:resources/>标签

mapping:将静态资源映射到指定的路径下

location:本地静态资源文件所在的目录

: <mvc:resources mapping="/statics/**" location="/statics/"></mvc:resources>

异常处理

1. 局部异常

  1)仅能处理指定Controller中的异常

  2)@ExceptionHandler

    例: @ExceptionHandler(value=RuntimeException.class)

      public String handlerException(RuntimeException e,HttpServletRequest req){

        req.setAttribute("error", e.getMessage());

        return "login";

      }

2. 全局异常

  1)对所有异常进行统一处理

  2)配置SimpleMappingExceptionResolver

    发生异常时使用对应的视图报告异常

    例:<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

        <property name="exceptionMappings">

          <props>

            <prop key="java.lang.RuntimeException">error</prop>

          </props>

        </property>

      </bean>

原文地址:https://www.cnblogs.com/yang82/p/8306071.html