spring的拦截器(MethodInterceptor)做权限验证,判断session里是否有值,可是拦截器里得不到session啊,怎么办?public class chkLoginAdvice implements MethodInterceptor{
//得不到session啊
}

解决方案 »

  1.   

    package com.yeezoo.tour.common.interceptor;import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
    import com.yeezoo.tour.common.util.IsNull;/**
     * 判断管理员是否登入,没有登入跳转到管理员登录页面
     * Copyright @ 2009 YeeZoo Tour
     * All right reserved.
     *
     * @author goxohu
     *
     */
    public class LoginAdminInterceptor extends AbstractInterceptor { @Override
    public String intercept(ActionInvocation invocation) throws Exception {
    Object obj = invocation.getInvocationContext().getSession().get("sessionAdmin");
    if(IsNull.isNull(obj)){//返回管理员登录页面
    return "toLoginPage";
    } else {
    return invocation.invoke();
    }
    }}
      

  2.   

    你不如用过滤器 HttpFilter 做!!
    spring的拦截器比较少见!不知道有没人这样做!
    Spring Security或acegi就是做权限验证验证的!
      

  3.   

    你这个是Struts2/webwork的拦截器,不是Spring
      

  4.   

    spring 的 MethodInterceptor 接口不能实现判断 session 中的值,
    建议 lz 使用 AbstractInterceptor.
      

  5.   

    我用的是struts1
    想用spring的拦截器解决
      

  6.   

    public class xxxSessionInterceptor extends HandlerInterceptorAdapter
    {
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler) 
    这里处理就可以~