用户的账号保存:
Map session = ActionContext.getContext().getSession();
session.put("user", user);而我在另一个Action里这样操作:获取不到user/
Map session = ActionContext.getContext().getSession();
String nameString = (String) session.get("user");但是我在jsp里,<s:property value="#session.user.name"/>都能获取到 很怪异哦???谢谢大家了!!!

解决方案 »

  1.   

    HttpSession session=ServletActionContext.getRequest().getSession();
    session.setAttribute();
    试试这个
      

  2.   


    还是不行 得到的是null值
      

  3.   

    User user = (User) session.get("user");
      

  4.   

    UserSession session=UserContext.getCurrentContext().getUserSession();我的项目也是用struts2 的 action中取session用的是上面的代码 但是会用到UserContext 是com.common.core.security.user.UserContext包下 需要:framework_core_4.0.jar 你看下你的项目中是否可以这样使用
      

  5.   

    UserSession 是com.common.core.security.user.UserSession包下的 也是在framework_core_4.0.jar 包中
      

  6.   

    你看看你的那两个发出和获取action分别是第几遍执行了,有可能是多次执行引起来的问题
      

  7.   

    我刚上传了framework_core_4.0.jar 到
    csdn 资源中  你下载下来试试
      

  8.   

    一直使用ServletActionContext.getRequest().getSession();没碰到过这个问题,LZ解决了的话,记得分享下。
      

  9.   

    然后我 user.getName(); //获取用户名
    在eclipse里打印出这样:cn.expert.model.modelBase.User@15b6116
      

  10.   

    你在另一个Action下添加代码如下,然后试试:
    ActionInvocation actinvo;
    ActionContext actcon=actinvo.getInvocationContext();Map session = ActionContext.getContext().getSession();
    String nameString = (String) session.get("user");
      

  11.   

    你是怎么set进去的 user
      

  12.   

    终于完成了User nameString =  (User) session.get("user");
    String nString =  nameString.getName().toString();谢谢大家啊!
      

  13.   

    Map session = ActionContext.getContext().getSession();User nameString =  (User) session.get("user");
    String nString =  nameString.getName().toString();忘记Map了 哈哈  再次谢谢大家啊!
      

  14.   

    String name = ((User) session.get("user")).getName();