zoukankan      html  css  js  c++  java
  • SpringMVC 拦截器实现

    SpringMvc实现拦截器方式一:

        <mvc:interceptors>
            <mvc:interceptor>
                <mvc:mapping path="/**"/>
                <bean class="xxx.UnLoginInteteceptor"></bean>
            </mvc:interceptor>
        </mvc:interceptors>

    SpringMvc实现拦截器方式二:

        <!-- 拦截器 -->
        <bean class="org.springframework.web.servlet.handler.MappedInterceptor">
            <constructor-arg >
                <!-- 配置拦截请求配置 -->
                <array>
                    <value>/**</value>
                </array>
            </constructor-arg>
            <constructor-arg>
                <!-- 配置拦截忽略配置 -->
                <array>
                    <value>/login/**</value>
                </array>
            </constructor-arg>
            <constructor-arg ref="unLogininterceptor"></constructor-arg>
        </bean>
        <bean name="unLogininterceptor" class="xxx.UnLoginInteteceptor"></bean>

    UnLoginInteteceptor.java文件内容

    package xxx.interceptor;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.subject.Subject;
    import org.apache.shiro.web.util.WebUtils;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    public class UnLoginIntereceptor implements HandlerInterceptor {
    
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, 
                Object obj, Exception e) throws Exception {
        }
    
        public void postHandle(HttpServletRequest request, HttpServletResponse response, 
                Object obj, ModelAndView view) throws Exception {
        }
    
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 
                Object obj) throws Exception {
            return true;
        }
    
    }
  • 相关阅读:
    web.xml中 error-page的正确用法
    5.项目数据库设计--人事管理系统
    mod_jk是Apache服务器的一个可插入模块
    jBox使用方法
    ApacheHttpServer出现启动报错:the requested operation has failed解决办法
    ApacheHttpServer修改httpd.conf配置文件
    redis client protocol 分解
    Andorid Async-HttpClient阅览
    HDU-2857-Mirror and Light(计算几何)
    xcode armv6 armv7 armv7s arm64
  • 原文地址:https://www.cnblogs.com/rainy-shurun/p/5148055.html
Copyright © 2011-2022 走看看