java action中session传值为空

HttpSession httpSession = ServletActionContext.getRequest().getSession();
httpSession.setAttribute("userName", member.getMemberName());
httpSession.setAttribute("userId", member.getMemberID());
httpSession.setAttribute("userAuthority", member.getMemberAuthority());
httpSession.setAttribute("userSex", member.getMemberSex());
httpSession.setAttribute("useDept", member.getDepartment().getDeptName());
responseText = "success";

 以上是 登陆action中赋值

下面是 其他的action中取值,之间是不是还要写其他的代码?

      HttpSession httpSession = ServletActionContext.getRequest().getSession();
        String name=httpSession.getAttribute("userName").toString();
        finance.setFinanceOperator(name);
        finance.setFinanceDate(enterStorehouse.getEnterTime());
        finance.setFinanceMoney(enterStorehouse.getEnterNumber()*enterStorehouse.getEnterPrice());
        finance.setFinanceType("支出");
        finance.setFinanceRemark("商品入库,产品为:"+goods.getGoodsName()+"供应商为:"+supplier.getSupplierName()+"单价为:"+enterStorehouse.getEnterPrice()+"数量为:"+enterStorehouse.getEnterNumber());
        financeService.save(finance);

 

如果你是用的struts2框架的话建议你用session.put("","")试试,然后用session.get("")得到

不知道为什么

不过提醒下:获取的session是同一个对象么?看看session的这个对象的hashcode