首页 > 其他 > 详细

struts 拦截器

时间:2014-04-05 21:55:26      阅读:533      评论:0      收藏:0      [点我收藏+]

网站开发的时候进行资源访问控制是必须的,经常使用的方式是在web.xml中添加过滤器进行资源过滤,在struts2中我们可以使用拦截器对资源进行控制

public class LoginInterceptor extends AbstractInterceptor
{
/*
* 进行登录拦截 看是否已经登入 (non-Javadoc) 相当于一个过滤器

* @see
* com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com
* .opensymphony.xwork2.ActionInvocation)
*/
@SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception
{
Map map = invocation.getInvocationContext().getSession();

//。。。其他逻辑

if (LoginImpl.class == invocation.getAction().getClass())
{
// 让登入的界面通过
return invocation.invoke();
}


if (map.get("login") == null)
{
// 返回登录界面
return Action.LOGIN;
}
return invocation.invoke();
}


}

struts 拦截器,布布扣,bubuko.com

struts 拦截器

原文:http://blog.csdn.net/cml_blog/article/details/22982395

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!