struts中的拦截器验证登录
2012-10-20 22:27
537 查看
权限验证拦截器PermissionInterceptor
//继承了AbstractInterceptor只需要重写intercept方法就可以了,省去了init()和destory()方法
Struts.xml配置
//因为验证是否登入是共用的,所以放在基包base中,在使用的时候必须要对添加的拦截器进行声明,并且还要将默认的拦截器加入不然就会失去默认拦截器的效果,
//继承了AbstractInterceptor只需要重写intercept方法就可以了,省去了init()和destory()方法
public class PermissionInterceptor extends AbstractInterceptor { //验证用户的权限 @Override public String intercept(ActionInvocation arg0) throws Exception { if(ActionContext.getContext().getSession().get("admin")==null) { //用户没有登入,保存提示信息到request中 ServletActionContext.getRequest().setAttribute("message","未登入,请先登入!"); //ActionContext.getContext().put("message","未登入,请先登入!"); return "nologin"; } //继续执行后续的action returnarg0.invoke(); } }
Struts.xml配置
//因为验证是否登入是共用的,所以放在基包base中,在使用的时候必须要对添加的拦截器进行声明,并且还要将默认的拦截器加入不然就会失去默认拦截器的效果,
<package name="base" extends="struts-default"> <!-- 拦截器的配置 --> <interceptors> <interceptor name="permissionInterceptor" class="interceptor.PermissionInterceptor"/> //声明 <interceptor-stack name="allInterceptor"> <!-- 必须包含原有的默认的defaultStack才会生效 --> <interceptor-ref name="defaultStack"/> //默认拦截器栈 <interceptor-ref name="permissionInterceptor"/> //引用 </interceptor-stack> </interceptors> <default-interceptor-ref name="allInterceptor"/> //默认拦截器设置 <global-results> <result name="ajax">/ajax.jsp</result> <result name="err">/err.jsp</result> <!-- 出现错误跳转到err.jsp --> <result name="nologin">/login.jsp</result> <!-- 没有登陆就跳转到login.jsp --> </global-results> </package>
相关文章推荐
- struts中用拦截器实现登录验证功能AuthorizationInterceptor
- 基于struts拦截器的登录验证
- Struts中的拦截器——登录验证实例
- Struts开发一个权限验证拦截器来判断用户是否登录
- 用struts拦截器实现登录验证功能AuthorizationInterceptor
- struts登录验证代码
- struts2 拦截器 登录验证
- springMVC拦截器进行登录验证
- ssm框架后台对app的接口进行登录验证(拦截器,更智能只要方法上面有这个定义注解就验证)
- struts自己定义拦截器--登录权限控制
- Struts 通过拦截器实现登录后跳转到登录前页面 处理普通Http请求和Ajax请求时拦截配置
- Struts拦截器拦截未登录的操作
- Struts 2+Jquery+JSON(登录验证)
- Struts2拦截器登录验证
- session验证登录状况拦截器以及XML配置
- myeclipse+struts登录界面 之 实现客户端验证
- Javascript验证Struts登录控件
- Struts实例详解1--登录验证
- Struts登录验证(防止未登录进入)
- JavaWeb -- Struts 自定义拦截器, 登录权限拦截