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完美了

转载于:https://www.cnblogs.com/LUA123/p/6950904.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值