日期:2014-05-19  浏览次数:20755 次

关于拦截器的问题 异常苦恼
Java code
@SuppressWarnings("serial")
public class MyInterceptor extends AbstractInterceptor {

    @SuppressWarnings("unchecked")
    @Override
    public String intercept(ActionInvocation arg0) throws Exception {
//      HttpSession  hs =   ServletActionContext.getRequest().getSession();
//        String username = (String) hs.getAttribute("username");
//      
      
                  ActionContext ac  =  arg0.getInvocationContext();
        Map session = ac.getSession();
    System.out.println(session.size());     
           Userinfo userinfo = (Userinfo) session.get("user");
           
            if(userinfo==null){
                return Action.LOGIN;
                
            }else{
            return arg0.invoke();
                
            }
            
           
    }

}

接受的前台数据总是为null 怎么办啊 有谁能帮忙啊

------解决方案--------------------
可能是struts配置拦截器的问题,配置例子如下:

Java code
<interceptors>
            <interceptor name="myInterceptor" class="cn.com.MyInterceptor"/>
            <interceptor-stack name="myInterceptorStack">
                <interceptor-ref name="defaultStack"/>
                <interceptor-ref name="myInterceptor"/>
            </interceptor-stack>
        </interceptors>
        <action name="list_*" class="cn.com.action.TheAction" method="{1}"> <!--拦截的TheAction中的方法-->
            <interceptor-ref name="myInterceptorStack" />
        </action>