使用拦截器栈



//使用拦截器栈
<!--最基本功能的拦截器栈的定义-->
<interceptor-stack name="basicStack">
 <interceptor-ref name="exception"/>
 <interceptor-ref name="servletConfig"/>
 <interceptor-ref name="prepare"/>
 <interceptor-ref name="checkbox"/>
 <interceptor-ref name="params"/>
 <interceptor-ref name="conversionError"/>
</interceptor-stack>
<!--在最基本功能的基础上增加数据校验功能的拦截器栈定义-->
<interceptor-stack name="validationWorkflowStack">
 <interceptor-ref name=basicStack/>
 <interceptor-ref name=validate/>
 <interceptor-ref name="workflow"/>
</interceptor-stack>
<!--在最基本的功能基础上增加上传文件功能的拦截器栈定义-->
<interceptor-stack name="fileUploadStack">
 <interceptor-ref name="fileUpload"/>
 <interceptor-ref name="basicStack"/>
</interceptor-stack>
<!--增加模型驱动功能的拦截器栈的定义-->
<interceptor-stack name="modelDrivenStack">
 <interceptor-ref name="modelDriven"/>
 <interceptor-ref name="basicStack"/>
</intercepor-stack>
<!--增加Action链拦截器的拦截器栈的定义-->
<interceptor-stack name="chainStack">
 <interceptor-ref name="chain"/>
 <interceptor-ref name="basicStack"/>
</interceptor>
<!--增加国际化支持的拦截器定义-->
<interceptor-stack name="i18nStack">
 <interceptor-ref name="i18n"/>
 <interceptor-ref name="basicStack"/>
</interceptor>
<!--Struts2,默认的拦截器-->
<interceptor-stack name="defaultStack">

</interceptor-stack>
//自定义拦截器(session过期,登陆有效性即操作的权限验证自定义拦截器)
public class LoginedCheckInterceptor extends AbstractInterceptor{
 /*拦截请求并进行登陆有效性验证*/
 public String intercept(ActionInvocation ai)throws Exception{
  //获取请求的URL
  String url=ServletActionContext.getRequest().getRequestURL().trim().toString();
  String prim=null;
  Admin admin;
  int index=0;
  //验证session是否过期
  if(!ServletActionContext.getRequest().isRequestedSessionIdValid()){
   //session过期,转向session过期页,最终跳转至登陆页面
   return "tologin";
  }else{
   admin=(Admin)ServletActionContext.getRequest().getSession().getAttribute("admin");
   if(admin==null){
    //尚未登陆,跳转登陆页面
    return "tologin";
   }
  }
 }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值