如果一个系统分为前台和后台,前台需要用户登录才能使用,后台需要管理员登录才能正常使用,
那么怎么样用struts2中的拦截器分别控制前后台的权限。
struts2 权限控制
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
- 拽拽的初行者 2010-05-18 07:43关注
简单的可以这样做:
[color=blue][b]STEP01 在Struts2的配置文件中,定义2个package:[/b][/color]
1个package是包括前台所有的Action
另一个package包括后台管理员的所有的Action。
[b][color=blue]
STEP02:然后定义一个AuthInterceptor,简单的这样写:[/color][/b][code="java"] public String intercept(ActionInvocation invocation) throws Exception {
Map<String, Object> map = invocation.getInvocationContext() .getSession(); User user = (User) map.get("user"); if (user == null) { return "login"; } else { return invocation.invoke(); } }[/code]
[color=blue]
[b]STEP03:将AuthInterceptor加入到管理员的那个package的默认InterceptorStack中。[/b][/color][code="xml"]
class="XXXX.AuthInterceptor" /><interceptor-ref name="defaultStack"/> <interceptor-ref name="authInterceptor"/> </interceptor-stack>
............[/code]
[color=blue][b]基本的权限检查完成![/b][/color]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥15 stable diffusion
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
- ¥15 perl MISA分析p3_in脚本出错
- ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
- ¥15 ubuntu虚拟机打包apk错误