今天在学习struts2的拦截器,课后老师让自己写一个token连接器,
大家没事瞅两眼!呵呵
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.TokenHelper;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class TokenInterceptor implements Interceptor {
public String intercept(ActionInvocation actionInvocation) throws Exception {
Object obj4= TokenHelper.getToken();
HttpSession session = ServletActionContext.getRequest().getSession();
Object obj = session.getAttribute("struts.token");
if(obj4.equals(obj)){
session.removeAttribute("struts.token");
actionInvocation.invoke();
}else{
return "fail";
}
return "success";
}