【发布时间】: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