<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 激活Spring注解方式:自动扫描,并注入bean --> <context:component-scan base-package="com.cmcc.aoi.selfhelp.action" /> <context:component-scan base-package="com.cmcc.aoi.selfhelp.wuxiancity.action" /> <!-- 配置视图解析 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 默认的注解映射的支持 --> <mvc:annotation-driven/> <bean id="authInterceptor" class="com.cmcc.aoi.selfhelp.interceptor.AuthInterceptor" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> </list> </property> </bean> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/selfhelp/**" /> <bean class="com.aoi.selfhelp.interceptor.AoiLoginAuthInterceptor" > <property name="excludeUrls"> <list> <value>/selfhelp/sysUser/create</value> <value>/selfhelp/sysUser/checkLoginName</value> <value>/selfhelp/sysUser/checkEmail</value> <value>/selfhelp/sysUser/save</value> <value>/selfhelp/email/sendActivationEmail</value> <value>/selfhelp/email/sendRetrievePasswordEmail</value> <value>/selfhelp/activation/prepareActivation</value> <value>/selfhelp/activation/activate</value> <value>/selfhelp/retrievePassword/retrievePassword</value> <value>/selfhelp/retrievePassword/sendEmail</value> <value>/selfhelp/retrievePassword/rePassword</value> <value>/selfhelp/tag/report</value> </list> </property> </bean> </mvc:interceptor> <!-- <mvc:interceptor> <mvc:mapping path="/selfhelp/deliverWebRequest/**" /> <bean class="com.aoi.selfhelp.interceptor.AoiAuthInterceptor" /> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/selfhelp/multiple/**" /> <bean class="com.aoi.selfhelp.interceptor.AoiAuthInterceptor" /> </mvc:interceptor> --> </mvc:interceptors> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="com.aoi.selfhelp.exception.AuthException">redirect:/user/login.action</prop> <prop key="com.aoi.selfhelp.exception.SelfHelpException">redirect:/user/staticPageAction.action?action=error</prop> </props> </property> <property name="defaultErrorView" value="../../common/error"></property> </bean> </beans>
package com.aoi.selfhelp.interceptor; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.ServletContext; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import com.aoi.selfhelp.entity.SysUser; public class AoiLoginAuthInterceptor implements HandlerInterceptor { private List<String> excludeUrls; public List<String> getExcludeUrls() { return excludeUrls; } public void setExcludeUrls(List<String> excludeUrls) { this.excludeUrls = excludeUrls; } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception { String requestUri = request.getRequestURI(); String contextPath = request.getContextPath(); String url = requestUri.substring(contextPath.length()); if (excludeUrls != null && excludeUrls.contains(url)) { return true; } else if (request.getSession().getAttribute("user") == null) { response.sendRedirect("/user/login.action"); return false; } // System.out.println("preHandle " + arg2); return true; } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3) throws Exception { // System.out.println("afterCompletion " + arg2); } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3) throws Exception { // System.out.println("postHandle " + arg2); } }
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
spring拦截器,高级参数绑定,controller返回值
AOP拦截器示例,告诉我们初学者理解aop,通过一个银行转帐说明问题。
NULL 博文链接:https://lpm528.iteye.com/blog/1259187
NULL 博文链接:https://rogerhunt.iteye.com/blog/608778
spring拦截器的简单例子.docx
spring mvc 拦截器获取请求数据信息 解压之后放到项目中 直接运行就可以了 (将流多次运用)
idea软件。SpringBoot的拦截器的博客所写的例子。preHandle()方法的返回值true和false的详细区别还未描述
这一版本的项目中新增了拦截器的一个demo
NULL 博文链接:https://bijian1013.iteye.com/blog/2142522
Spring AOP 拦截器 Advisor Spring AOP 拦截器 Advisor
Spring AOP四种创建通知(拦截器)类型
使用CGLIB编写的Spring的拦截器 非常使用的哦
Spring MVC 拦截器Spring MVC 拦截器
spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截
主要介绍了Spring拦截器HandlerInterceptor接口代码解析,具有一定借鉴价值,需要的朋友可以参考下
初学者很容易将 Spring MVC 拦截器 和 Spring Cloud OpenFeign 拦截器搞混,误以为OpenFeign拦截器就是SpringMVC拦截器:Spring MVC拦截器发生在客户端 和 服务端之间,在客户端向服务端发送请求时进行拦截处理。...
NULL 博文链接:https://269181927.iteye.com/blog/788426
自己spring boot 拦截器,可以自定义限制跳转路径及自定义不拦截哪些具体路径,具体设置可以看注释,一看就懂,引用哪些包已经包含了,不明白的请浏览,看到后第一时间给您回复
本篇文章主要介绍了使用spring拦截器实现日志管理实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。