zoukankan      html  css  js  c++  java
  • shiro+SpringMVC 项目 配置404页面

    说的配置404,大家都会想到去web.xml里面配置

        <error-page>
            <error-code>404</error-code>
            <location>/404.html</location>
        </error-page>

    可是如果我有业务需求,当发生404,我要记录相关信息呢?或者说404的展示页面我也有需要动态获取的资源呢?那么静态页面就力不从心了。

    那么先写一个处理404的方法

        //404
        @RequestMapping(value="/404")
        public String notFound(){
            //do something
            return "404";
        }

    用过springmvc的我就不解释上面代码了

    接下来配置web.xml(说实话我傻逼似的一直认为这里只能配置静态资源,涨姿势了)

        <error-page>
            <error-code>404</error-code>
            <!-- 这里可以为servlet,不一定非要静态资源 -->
            <location>/404</location>
        </error-page>

    如果你项目中没用到shiro的就可以到此为止了

    shiro项目会报错:

    org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code

    经网上查看便知

    在web.xml的配置文件里面,应该这样配置shiro

        <!-- Shiro Filter is defined in the spring application context: -->
        <filter>
            <filter-name>shiroFilter</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
            <init-param>
                <param-name>targetFilterLifecycle</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>shiroFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>INCLUDE</dispatcher>
            <dispatcher>ERROR</dispatcher>
        </filter-mapping>

    重点是

            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>INCLUDE</dispatcher>
            <dispatcher>ERROR</dispatcher>

    这几行代码。

    到此运行工程,404完美了

  • 相关阅读:
    Java——class对象
    Java——HashSet和TreeSet的区别
    Java——普通数据类型转化为String
    Java——Iterator迭代器
    Java——ArrayList和LinkedList的区别(转)
    Java——警告消除
    Object类——toString
    Java——动态调用类中方法
    SharePoint使用jsom查询当前用户信息
    SharePoint列表模板(.stp)
  • 原文地址:https://www.cnblogs.com/LUA123/p/6950904.html
Copyright © 2011-2022 走看看