LoginInterceptor (用户登录拦截器类)

public class LoginInterceptor extends MethodFilterInterceptor {


    @Override
    protected String doIntercept(ActionInvocation invocation) throws Exception {
       // TODO Auto-generated method stub
       ActionContext context = invocation.getInvocationContext();
       Map session = context.getSession();
      
       try {
           TbUser user = (TbUser) session.get("user");
           if (user != null) {
             
              return invocation.invoke();
           }
           else {
              context.put("login"," please to login again" );
              return ActionSupport.LOGIN;
           }
       } catch (Exception e) {
           // TODO: handle exception
           context.put("login"," please to login again" );
           return ActionSupport.LOGIN;
       }
    }




}

你可能感兴趣的:(Interceptor)