import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; @Aspect
public class demoInterceptor { private demoInterceptor() { }; @Pointcut("execution(* com.demo.controller.login(..))")
private void interceptor() {
}; @Around("interceptor()")
public Object aroundLogin(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = null;
HttpServletResponse response = null;
Object[] args = point.getArgs();
for (int i = ; i < args.length; i++) {
if (args[i] instanceof HttpServletRequest) {
request = (HttpServletRequest) args[i];
}
if (args[i] instanceof HttpServletResponse) {
response = (HttpServletResponse) args[i];
} }
if (request.getParameter("j_username").equals("demo")) { return point.proceed();
} else {
response.sendRedirect("/login.do");
return null;
}
}
}

aop-config.xml

<?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:aop="http://www.springframework.org/schema/aop"
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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<aop:aspectj-autoproxy/>
<bean class="demoInterceptor"/>
</beans>

转自:http://www.iprotoss.com/?p=130

Spring AOP实现拦截转发控制的更多相关文章

  1. Spring Aop、拦截器、过滤器的区别

    Filter过滤器:拦截web访问url地址.Interceptor拦截器:拦截以 .action结尾的url,拦截Action的访问.Spring AOP拦截器:只能拦截Spring管理Bean的访 ...

  2. 基于Spring AOP实现的权限控制

    1.AOP简介 AOP,面向切面编程,往往被定义为促使软件系统实现关注点的分离的技术.系统是由许多不同的组件所组成的,每一个组件负责一块特定的功能.除了实现自身核心功能之外,这些组件还经常承担着额外的 ...

  3. spring---aop(3)---Spring AOP的拦截器链

    写在前面 时间断断续续,这次写一点关于spring aop拦截器链的记载.至于如何获取spring的拦截器,前一篇博客已经写的很清楚(spring---aop(2)---Spring AOP的JDK动 ...

  4. spring aop实现拦截接口请求打印日志

    在spring配置 1编写自己的注解类 2.编写注解解析类 3.配置spring aop代理 (下面我使用注解 如使用配置 配置切点即可,有两种代理默认jdk代理 设置true 为cglib代理) / ...

  5. Spring AOP无法拦截内部方法调用

    当在同一个类中,A方法调用B方法时,AOP无法工作的问题 假设一个接口里面有两个方法: package demo.long; public interface CustomerService { pu ...

  6. Spring AOP不拦截从对象内部调用的方法原因

    拦截器的实现原理很简单,就是动态代理,实现AOP机制.当外部调用被拦截bean的拦截方法时,可以选择在拦截之前或者之后等条件执行拦截方法之外的逻辑,比如特殊权限验证,参数修正等操作. 但是最近在项目中 ...

  7. 利用Spring AOP机制拦截方法一例

    直接上代码: @Aspect // for aop @Component // for auto scan @Order(0) // execute before @Transactional pub ...

  8. Spring AOP无法拦截Controller中的方法

    想使用AOP Annotation配置Spring MVC的Controller进行拦截, 发现无法拦截Controller的方法, 却可以拦截Service层的方法. 一开始: Spring的配置文 ...

  9. spring aop无法拦截类内部的方法调用

    1.概念 拦截器的实现原理就是动态代理,实现AOP机制.Spring 的代理实现有两种:一是基于 JDK Dynamic Proxy 技术而实现的:二是基于 CGLIB 技术而实现的.如果目标对象实现 ...

随机推荐

  1. Mysql启动服务提示系统找不到指定的文件

    Mysql启动服务: C:\Windows\system32>net start mysql发生系统错误 2. 系统找不到指定的文件. 怎么还是报这个错?难道不是由于配置的原因?对,不是由于上面 ...

  2. AJAX--前后台交互

    注:ajax通过async参数决定是异步还是同步,false同步,true异步; 异步执行顺序是先执行后续动作,再执行success里代码; 同步是先执行success里代码,再执行后续代码; 验证: ...

  3. .tar与.gz有什么联系与区别?

    我们在windows下经常进行压缩解压等操作.在linux上也经常会用到,但是比较常见的是.tar.gz 很多人见到就条件反射,压缩用czvf,解压用xzvf.但是,你真的了解这个后缀名吗? 其实: ...

  4. jquery请求格式和返回类型 汇总

    常规请求基本格式 1 [WebMethod] 2 public string SayHello(string name) 3 { 4 return "Hello " + name; ...

  5. HUST-1350 Trie

    1350 - Trie 时间限制:1秒 内存限制:128兆 104 次提交 35 次通过 题目描述 In computer science, a trie, is an ordered tree da ...

  6. KVM(六)Nova 通过 libvirt 管理 QEMU/KVM 虚机

    1. Libvirt 在 OpenStack 架构中的位置 在 Nova Compute 节点上运行的 nova-compute 服务调用 Hypervisor API 去管理运行在该 Hypervi ...

  7. 深入解析当下大热的前后端分离组件django-rest_framework系列一

    前言 Nodejs的逐渐成熟和日趋稳定,使得越来越多的公司开始尝试使用Nodejs来练一下手,尝一尝鲜.在传统的web应用开发中,大多数的程序员会将浏览器作为前后端的分界线.将浏览器中为用户进行页面展 ...

  8. radio和label关联问题,点击label改变颜色

    $(function () { $("#fangan :radio[name='price']").bind('click', function (event) { //$(thi ...

  9. centos6.5 中文输入法图标和提示都不见了【解决】

    原因python升级引起的 两步解决: # vi /usr/bin/ibus-setup # vi /usr/libexec/ibus-ui-gtk 把这两个文件中的exec python 修改为 e ...

  10. 【转载】【bitset】C++ STL bitset 使用总结

    C++ bitset类的使用与简介 有些程序要处理二进制位的有序集,每个位可能包含的是0(关)或1(开)的值.位是用来保存一组项或条件的yes/no信息(有时也称标志)的简洁方法.标准库提供了bits ...