zoukankan      html  css  js  c++  java
  • Struts2 框架下 session 读出来为null

    我用的strust2框架,开始的时候这么写的:

    在 登陆函数中(注释部分):

    public String dealerLogin(){
            EntityInfo entityinfo=dealerservice.dealerLogin(super.account,super.password);
               if(entityinfo!=null){
    /*             ActionContext ac = ActionContext.getContext();我开始用的这种方式写入到session中
                   ac.getSession().put(KeyConstant.MANAGER,entityinfo); */
                   ServletActionContext.getRequest().getSession().setAttribute(KeyConstant.MANAGER,entityinfo);
                   return "dealertlogin";
               }
               else{
                   return "false";
               }
        }

    用的时候的函数:

    public String addAllMachCode(){
            String[] machinearrs=machinearr.split(";");
            int dealerId=0;
    /*        HttpServletRequest request=ServletActionContext.getRequest();
            HttpSession session=request.getSession();
            EntityInfo entityinfo=(EntityInfo) session.getAttribute(KeyConstant.MANAGER);*/这里读出来  entityinfo是null
            EntityInfo entityinfo= (EntityInfo) ActionContext.getContext().getSession().get(KeyConstant.MANAGER);
            Dealer dealer= entityinfo.getDealer();
            dealerId=dealer.getDEALER_ID();
            for (String machinecode :machinearrs) {
                
                addAMachCode(machinecode,dealerId);
            }
            return SUCCESS;
        }

    这到底是为什么了:
    提取出来 第一种: 写入 ActionContext ac = ActionContext.getContext();
                   ac.getSession().put(KeyConstant.MANAGER,entityinfo)
              读取: HttpServletRequest request=ServletActionContext.getRequest();
                   HttpSession session=request.getSession();
                  EntityInfo entityinfo=(EntityInfo) session.getAttribute(KeyConstant.MANAGER);
          第二种:写入   ServletActionContext.getRequest().getSession().setAttribute(KeyConstant.MANAGER,entityinfo);
              读取: EntityInfo entityinfo= (EntityInfo) ActionContext.getContext().getSession().get(KeyConstant.MANAGER);
    有没有人解释下 为什么  
  • 相关阅读:
    网页弹窗代码大全收集整理
    再来二十一段救命的PHP代码
    PHP文件包含漏洞原理分析和利用方法
    Apache重写规则的常见应用及实例说明
    PHPCMS 整站代码分析讲解(一)
    网络登录过程
    lamp安装的所有注意事项
    使用lockbits方法处理图像 from http://blog.sina.com.cn/s/blog_4e3e2ce4010009on.html
    CImage类 from http://www.cnblogs.com/afarmer/archive/2012/03/31/2427273.html
    VC/MFC怎样将位图CBitmap对象保存成为bmp格式文件? from http://coding1688.iteye.com/blog/1547035
  • 原文地址:https://www.cnblogs.com/softwarewebdesign/p/5574955.html
Copyright © 2011-2022 走看看