• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
helong
博客园    首页    新随笔    联系   管理    订阅  订阅

使用struts2 拦截器实现判断是否登录功能

package com.iapppay.maintain.common;

import java.util.Map;

import org.jasypt.commons.CommonUtils;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class LoginInterceptor extends MethodFilterInterceptor {

private static final long serialVersionUID = 3590018080122600795L;
@Override
protected String doIntercept(ActionInvocation arg0) throws Exception {
ActionContext act=arg0.getInvocationContext();
Map session = act.getSession();
String user=(String) session.get("user");
if(!CommonUtils.isEmpty(user)){
return arg0.invoke();
}
return Action.LOGIN;
}
}

struts.xml配置

<interceptors>
<interceptor name="loginInterceptor" class="com.iapppay.maintain.common.LoginInterceptor" />
<interceptor-stack name="maintainInterceptor">
<interceptor-ref name="loginInterceptor">
<param name="excludeMethods">index,login</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="maintainInterceptor" />



posted @ 2011-09-28 10:37  helong  阅读(444)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3