首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

struts2 阻截配置

2012-09-02 
struts2 拦截配置??? constant namestruts.enable.DynamicMethodInvocation valuetrue /??? cons

struts2 拦截配置


??? <constant name="struts.enable.DynamicMethodInvocation" value="true" />
??? <constant name="struts.devMode" value="true" />
???
??? <package name="com" extends="struts-default">
??? ??? <interceptors>???
??????????? <interceptor name="sessionout"?
???????????? />??
??????????????? <interceptor-ref name="sessionout"/>?
??????????? </interceptor-stack>?
??????? </interceptors>?
??? ???
??? ??? <default-interceptor-ref name="mydefault"/>
??? ???
??? ??? <global-results>
??? ??????? <result name="login">/index.jsp</result>
??? ??? </global-results>

?

?

?

?

?

package com.joyveb.jlbos.interceptor;

import java.util.Map;

import com.joyveb.jlbos.action.LoginAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SessionInterceptor extends AbstractInterceptor {

??? ?@Override?
??? ??? public String intercept(ActionInvocation actionInvocation) throws Exception {?
??? ??????? ActionContext ctx = ActionContext.getContext();?
??? ??????? Map<String,Object> session = ctx.getSession();?
??? ??????? Action action = (Action) actionInvocation.getAction();?
??? ??????? if (action instanceof LoginAction) {?
??? ??????????? return actionInvocation.invoke();?
??? ??????? }?
??? ??????? String userName = (String) session.get("userName");?
??? ??????? if (userName == null) {?
??? ??????????? return Action.LOGIN;?
??? ??????? } else {?
??? ??????????? return actionInvocation.invoke();?
??? ??????? }?
??? ??? }?

}

热点排行