您的位置:首页 > 其它

ssh登录拦截器配置

2015-07-22 22:55 344 查看
struts.xml的配置

<interceptors>
<interceptor name="LoginInterceptor" class="com.jeizas.Interceptor.LoginInterceptor"></interceptor>
<interceptor-stack name="LoginInterceptorStack">
<interceptor-ref name="LoginInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<interceptor-ref name="LoginInterceptorStack"><interceptor-ref>


java文件配置

import java.util.Map;

import com.opensymphony.xwork2.Action;
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 = 1L;

@Override
public String intercept(ActionInvocation arg0) throws Exception {
// TODO Auto-generated method stub
String actionName = arg0.getInvocationContext().getName();//获得当前要调用的action
if(actionName == "LoginUserAction"){//登录所用的action放行
return arg0.invoke();
}
Map<String,Object> session=ActionContext.getContext().getSession();
Object user=session.get("loginUser");//从session中获得登录用户
if(user != null){
return arg0.invoke();
}else{
return Action.LOGIN;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: