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

最新文章

  1. Python之路 day3 全局变量、局部变量
  2. Swift完整项目打包Framework,嵌入OC项目使用
  3. android之inflater用法
  4. Emmet插件使用方法总结
  5. 【windows核心编程】使用远程线程注入DLL
  6. 【转】stdin, stdout, stderr 以及重定向
  7. Reids详解-抄本
  8. [bzoj4872]分手是祝愿
  9. class对象详解
  10. String方法
  11. leetcode 639 Decode Ways II
  12. 支持pc和移动端的手写签批功能
  13. 解决wxParse空格不解析的问题
  14. awk 相关的复习
  15. Navicat备份、还原mysql数据库
  16. java 日期工具类DateUtils
  17. C# 将 Stream 写入文件
  18. Java-Runoob-高级教程-实例-数组:06. Java 实例 – 数组获取最大和最小值
  19. maven - 配置强制从指定仓库拉取jar包
  20. maven将镜像站点改为中国开源镜像点

热门文章

  1. java 定时器的三种方式
  2. 同源、同源策略、跨域问题、django解决方案
  3. Selenium2+python自动化22-发送各种类型附件邮件【转载】
  4. activiti-ui源码构建
  5. qt include_directories没用
  6. win上安装Redis并将其设置为服务
  7. Python3中的新特性(2)——常见陷阱
  8. Vue 不使用Vuex的情况下进行状态管理
  9. docker 与 yarn
  10. hdu6231