【问题标题】:Struts2 - retrieve session object using another session object as keyStruts2 - 使用另一个会话对象作为键检索会话对象
【发布时间】:2012-06-01 06:40:50
【问题描述】:

我是 struts2 的新手,我正在尝试使用动态会话密钥检索会话对象。

我的应用流程是这样的:用户将通过浏览器点击操作

http://localhost:8080/prjcr/pad.action?userid=p02585@test.org 

在操作类中,我使用 p02585@test.org 请求参数从 Web 服务检索值列表,并将它们存储在会话中,如下所示:

//get the request parameter
userid=ServletActionContext.getRequest().getParameter("userid);    
QDefn[] qDefn = proxy.getQDefns(userid); //webservice call   
List<QDefn> qdList = new ArrayList<QDefn>();   
qdList.add(Arrays.asList(qDefn));  

提取请求参数的userid部分作为会话密钥

userid = userid.substring("UserId", userid.substring(0, userid.indexof('@'));   
//The key itself is what we receive in the request parameter  
ActionContext.getContext().getSession().put("UserId", userid);      

然后将相关的值列表推送到会话中

ActionContext.getContext().getSession().put(userid, qdList);  

并转发到一个 JSP,该 JSP 在选择下拉列表中显示此列表,如下所示:

<s:select name="qdefn" 
id="qdefn" 

list="#session.%{#session.UserId}"  ---What is the notation here??

listKey="defnName"
listValue="defnName"
headerKey="ALLQD"
headerValue="All" > </s:select>  

我尝试使用动态会话密钥(即用户 ID)从 jsp 中的会话中提取 qdList。 在 java 中,我们将其作为 session.get(userid) 进行。我还不能理解 OGNL 符号。所以,我不知道如何在 Struts2/OGNL 中做到这一点。

提前致谢

【问题讨论】:

    标签: java javascript jsp struts2


    【解决方案1】:

    如果你做一个

    System.out.println(ActionContext.getContext().getSession().getClass());
    

    在你的行动中你会得到'class org.apache.struts2.dispatcher.SessionMap',但如果你做了一个

    out.println(session.getClass());
    

    在你的jsp中你会得到'class org.apache.catalina.session.StandardSessionFacade'或类似的东西(我使用tomcat)

    那就试试吧

    session.getAttribute(userid);
    

    而不是

    session.get(userid);
    

    【讨论】:

    • 您好。感谢您的回复。您的意思是建议在 jsP 的 select 标记中使用如下所示的 list 属性吗? list=session.getAttribute(userid)。那会奏效吗?此外, session.getAttribuet(userid) 只会让我得到我应该用来获取相应列表的用户 ID。像这样的东西:session.getAttribute(session.getAttribute(userid))。我怎样才能在 OGNL 表示法中做到这一点?我想知道,这可能吗?虽然,我不知道,但这并不意味着不可能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2011-10-15
    • 2010-09-06
    • 1970-01-01
    • 2022-01-25
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多