希望有例子的哥们姐妹直接给个例子说明,代码详细点,谢谢!

解决方案 »

  1.   

    package com.interceptor;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 Auth extends AbstractInterceptor { public String intercept(ActionInvocation ai) throws Exception 
    {
    Map  map=ai.getInvocationContext().getSession();

     if(map.get("user")==null)

     {  ActionContext.getContext().put("message", "请您先登录在进行操作!");
      System.out.println("请您先登录在进行操作!");
    return Action.LOGIN;
        }
     else

     {     
    String result=ai.invoke();
    return result;
    }

    }}在你的登陆action中判断输入的账号密码是不是对的如果是对的话就ActionContext.getContext().getSession().put("user","id");
    这样在拦截器根据get出来的是否有值就可以判断是否登录!
    仅供参考...