servlet 的init方法中给usersIP存了个map如下代码   servletConfig.getServletContext().setAttribute("usersIP", new HashMap());
action层通过这样的方式取usersIP,
 ((HashMap)ServletActionContext.getServletContext().getAttribute("usersIP")).put(user.getLoginId(), localip);红色部分取不到,为空指针哪位前辈指教下,哪里出错了?100

解决方案 »

  1.   

    ServletActionContext.getServletContext() 这个context得到了吗还有可以的话确认下 取时的ServletContext和存时的ServletContext是不是同一个?
      

  2.   

    用this.getServletContext().getAttribute("usersIP")感觉ServletActionContext和ServletContext混淆了
      

  3.   

    代码没有问题,web.xml文件出了点问题。
      

  4.   

    你在servlet的init中用色素死哦你保存:usersIP存了个map
    session.setAttribute("usersIP", new HashMap());在action层通过这样的方式取usersIP,
    ((HashMap)ServletActionContext.getRequest().getSession().getAttribute("usersIP")).put(user.getLoginId(), localip);