1 import javax.servlet.http.HttpSession;
2
3 import org.aopalliance.intercept.Invocation;
4 import org.apache.struts2.ServletActionContext;
5
6 import com.dkx.action.UserAction;
7 import com.opensymphony.xwork2.ActionInvocation;
8 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
9
10 public class Userinteceptor extends AbstractInterceptor{
11
12 @Override
13 public String intercept(ActionInvocation a1) throws Exception {
14 if (a1.getAction().getClass()==UserAction.class) {
15 return a1.invoke();
16 }
17 HttpSession session=ServletActionContext.getRequest().getSession();
18 Object obj=session.getAttribute("name");
19 if (obj!=null) {
20 return a1.invoke();//继续执行
21 }else {
22 return "login";
23 }
24
25 }
26
27 }