1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| package com.inter;
import java.util.Map;
import com.obj.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class CheckInterceptor extends AbstractInterceptor{
private static final long serialVersionUID = 1;
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String intercept(ActionInvocation arg0) throws Exception {
ActionContext actionContext = arg0.getInvocationContext();
Map<?, ?> sessionMap = actionContext.getSession();
String name = user.getName();
if(name != null && name.equals("ttnezpwinf")){
return arg0.invoke();
}
actionContext.put("tip", "請先登入!");
return Action.LOGIN;
}
}
|