使用Struts2的拦截器实现权限控制
来源:互联网 发布:压缩照片的软件 编辑:程序博客网 时间:2024/05/16 12:59
使用spring 的AOP实现权限控制,直接使用了struts2 提供的ActionContext,使spring和struts耦合在一起,从这个角度考虑,直接使用struts的拦截器更合适.
使用struts的拦截器,要实现Interceptor,今天没有遇到什么问题,调试也很顺利,代码如下:
package bbs.web.interceptor;
import bbs.domain.bean.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class LoginInterceptor extends AbstractInterceptor{
/**
*
*/
private static final long serialVersionUID = 5729500231434275095L;
@Override
public String intercept(ActionInvocation arg0) throws Exception {
User user = (User) ActionContext.getContext().getSession().get("user");
if (user == null)
return "login";
return arg0.invoke();
}
}
在struts.xml配置:
<interceptors>
<interceptor name="loginInterceptor" class="bbs.web.interceptor.LoginInterceptor"></interceptor>
</interceptors>
...
<action name="board_*" class="boardAction" method="{1}">
<result name="success">/boardlist.jsp</result>
<result name="error">/{1}board.jsp</result>
<result name="login">/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="loginInterceptor"></interceptor-ref>
</action>
注意一点,拦截器使用要明确指定使用defaultStack,否则,struts默认的拦截器就不启用了.
做权限控制,还可以使用filter.
- 使用Struts2的拦截器实现权限控制
- 使用Struts2的拦截器实现权限控制
- struts2 实现权限控制拦截器
- struts2拦截器实现权限控制
- struts2拦截器实现权限控制
- Struts2—拦截器实现权限控制
- struts2拦截器实现权限控制
- struts2 使用注解、反射、拦截器实现基于方法的权限控制
- 使用Struts2的拦截器和自定义注解方式实现权限控制
- 基于Struts2拦截器的权限控制
- Struts2拦截器 实现未登录拦截和权限控制
- Struts2拦截器 实现未登录拦截和权限控制
- Struts2权限控制拦截器
- Struts2权限控制拦截器
- Struts2-拦截器-权限控制
- 使用拦截器实现权限控制
- 在struts2.1中使用注解和拦截器实现权限细粒度控制
- 在struts2.1中使用注解和拦截器实现权限细粒度控制
- 一份比较详细的DOS命令说明
- DDD动态查看内核
- reactos操作系统实现(146)
- 网页播放flash没有声音和Firefox无法安装插件的问题
- 想成功必须养成的十大习惯
- 使用Struts2的拦截器实现权限控制
- 生活工作中应有的20个好习惯
- Linux下Red5安装配置
- ubuntu 启动root账户
- 请大家给我点意见~本人大3了,还一无所知~
- 一堂价值39万元的课,把它看完,你一定会有收获
- Java优秀书籍推荐
- 常用的CMD网络命令
- Word页码随意定