我创建了一个AuthInterceptor用于登录认证的拦截器,但是在里面通过,
invocation.getSessionAtrr()获取Sesssion里的User对象为什么是空的
public class AuthInterceptor implements Interceptor { public void intercept(Invocation invocation) { Controller controller = invocation.getController(); User user = controller.getSessionAttr(User.LOGIN_SESSION_NAME); //这里的user是null,为什么 System.out.println("user:" + JSON.toJSONString(user,true)); if (null == user) { controller.redirect("/login"); } else { invocation.invoke(); } } } public class LoginController extends Controller { private ILoginService loginService = new LoginServiceImpl(); @Clear(AuthInterceptor.class) public void index() { renderJsp("login.jsp"); } @Clear(AuthInterceptor.class) public void validate() { String account = getPara("account"); String password = getPara("password"); try { User user = loginService.login(account,password); if (null != user) { this.setSessionAttr(User.LOGIN_SESSION_NAME,user); redirect("/index"); } else { redirect("/login"); } } catch (Exception e) { e.printStackTrace(); } } }