博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Struts2自定义拦截器
阅读量:4709 次
发布时间:2019-06-10

本文共 1727 字,大约阅读时间需要 5 分钟。

1. 需求

自定义拦截器实现,用户登录的访问控制。

2. 定义拦截器类

1 public class LoginInterceptor extends AbstractInterceptor 2 { 3  4     @Override 5     public String intercept(ActionInvocation ai) throws Exception 6     { 7         // TODO Auto-generated method stub 8         System.out.println("--------------intercept"); 9         String methodName = ai.getProxy().getMethod(); //获得被拦截的方法名字10         System.out.println("=============" + methodName);11         if (methodName.equals("userLogin"))12         {13             return ai.invoke();//放行:继续向下执行14         }15         //获得登陆成功之后,会话对象封装的数据16         Object obj = ai.getInvocationContext().getSession().get("user");17         if (obj == null)18         {19             return Action.LOGIN;  //跳转到登陆页面20         } else21         {22             return ai.invoke();//放行:继续向下执行23         }24     }25 }

3. 配置拦截器

1 
2 5
6
7
8
9
[A2] 10
11
12
13
14
15
16 17
18
19
WEB-INF/jsp/login.jsp
20
21 22
24
25
26
/index.jsp
27
/index.jsp
28
WEB-INF/jsp/show.jsp
29
30
31
WEB-INF/jsp/show.jsp
32
33
34
35
36

 

转载于:https://www.cnblogs.com/guanghe/p/6063050.html

你可能感兴趣的文章
Asp.net 对于服务器控件添加Client端方法
查看>>
在Salesforce中创建Approval Process
查看>>
NFS服务搭建与配置
查看>>
python计算文件md5值
查看>>
android 4.1 Emulator Skins
查看>>
Android 手机 ADB FastBoot 命令基本用法
查看>>
各种排序总结(总)
查看>>
《天天来塔防》游戏分析
查看>>
jquery事件
查看>>
selenium + ChromeDriver 实战系列之启信宝(一)
查看>>
iphone中input按钮设置disabled属性出现灰色背景没有显示问题
查看>>
谈谈毕业后第一份工作和追女生的问题
查看>>
程序数据集算地数据库
查看>>
LinkedHashMap,TreeMap和Hashtable子类Properties
查看>>
swift基础语法(01-常量与变量)
查看>>
JavaScript基本概念(变量和数据类型)
查看>>
6 tips for recovering from a flop
查看>>
ArrayList、Vector、HashMap、HashTable、HashSet的默认初始容量、加载因子、扩容增量...
查看>>
Ubuntu14设置静态IP的地方
查看>>
计算几何 部分模板
查看>>