public class AuthorizationPermissionInterceptor implements MethodBeforeAdvice{
   public void before(Method methodName, Object[] objs, Object obj) throws Throwable {  }
}
拦截器的配置如下:
<bean id="aroundAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
   <property name="advice">
       <ref local="permissionInterceptor"/>
   </property>
   <property name="pattern">
  <value>.*Service.*(..)</value>
   </property>
</bean>做权限方面的验证,想使用拦截器来拦截,使用的是方法的拦截。
现在的问题是我如何在拦截的before中获得session?有这方面的朋友,请帮忙,谢谢!

解决方案 »

  1.   

    给个思路:
    http://zg770423.blog.163.com/blog/static/13826688820112275259181/
    希望可以帮助到你
      

  2.   

    写一个类存放session
    public class SessionStore {   
        private static ThreadLocal mySession = new ThreadLocal();   
            
        public static HttpSession getWebSession() {
          HttpSession session = (HttpSession) mySession.get();
          return session;
        }     public static void setWebSession(HttpSession session) {
           mySession.set(session);
        }
    }  写一个filter
    public class GetSessionFilter implements Filter {   
        
        public void doFilter(ServletRequest request, ServletResponse response,   
                FilterChain filter) throws IOException, ServletException {   
            SessionStore.setRequest((HttpServletRequest) request);   
            SessionStore.setResponse((HttpServletResponse) response);   
            filter.doFilter(request, response);   
        }   
    } web.xml配置filter    <filter>  
             <filter-name>GetSessionFilter</filter-name>  
             <filter-class>com.cn.GetContent</filter-class><!-配置正确包名-->  
        </filter>  
        <filter-mapping>  
            <filter-name>GetSessionFilter</filter-name>  
            <url-pattern>/*</url-pattern>  
        </filter-mapping>  aop类的before方法直接就可以得到了HttpSession session = SessionStore.getSession();   
      

  3.   

    用到struts2么?HttpSession session = ServletActionContext.getRequest().getSession();