页面之间共享数据,比如登录的用户名,权限等,session2中有哪些处理方法。
我实现SessionAware接口,好像不行。

解决方案 »

  1.   

    request.getSession().getAttribute()
    request.getSession().setAttribute()
    简单好用
      

  2.   

    1解耦和的方法使用com.opensymphony.xwork2.ActionContext类public Map getSession()具体使用: 
    Map session = context.getSession();
    这里的session在struts2里被包装成了Map类型然后就是楼主使用的方法
    使用SessionAware接口2耦和的方法public static HttpServletRequest GetRequest()使用:
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();以上所说的耦合都是指与Servlet API耦合的意思
      

  3.   

    用戶登錄直接从数据库查询一条实体记录,然后保存在session里
    存入session:request.getSession().setAttribute("key","value") 
    从session读取:request.getSession().getAttribute("key") 
    注:如果session中存放的是实体类,取出来要进行强转
    如:比如是User类
    从session读取:(User)request.getSession().getAttribute("USER")
    USER是自定义的键
      

  4.   

    用戶登錄直接从数据库查询一条实体记录,然后保存在session里 
    存入session:request.getSession().setAttribute("key","value") 
    从session读取:request.getSession().getAttribute("key") 
    注:如果session中存放的是实体类,取出来要进行强转 
    如:比如是User类 
    存入session:request.getSession().setAttribute("USER",user) 
    从session读取:(User)request.getSession().getAttribute("USER") 
    USER是自定义的键 
    user是用户登录后获取的一个实体记录
      

  5.   

    session.setAttribute("key",value);
    session.getAttribute("key");一般如果你没有设置关闭SESSION的话,服务器会自动创建一个SESSION来使用,可以直接使用两个方法,当然,自己创建个SESSION也很好的哈。
      

  6.   

    1>.ActionContext类:
       ActionContext ac = ActionContext.getContext();
       Map sessionMap = ac.getSession();2>.ServletActionContext类:直接返回Http对象。
       String name = ServletActionContext.getRequest().getParameter("name");
       Map sessionMap = ServletActionContext.getRequest().getSession();3>.IOC访问:
       struts2中可以通过IOC(依赖注入)将Servlet对象注入到Action中,这一组接口都由Aware结尾。