@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 怎么办啊 有谁能帮忙啊

解决方案 »

  1.   

    你是不是把正常的登录请求也全都给拦截了?导致负责登录的servlet都没机会往session中放 user
      

  2.   

       非正常登陆直接被拦截 这个正常   但正常登陆是用户名密码被action传到拦截器 传的参数总为null 
      

  3.   

    应该不是拦截器本身的问题,是拦截器配置的问题,或之前根本就没有把user放到session中。
    这里不使用拦截器,直接进action,楼主试试,应该也一样取不取session中的user。
      

  4.   

    可能是struts配置拦截器的问题,配置例子如下:<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>