我是 struts2 新手,我正在尝试使用动态 session key 检索 session 对象。
我的应用程序流程如下:用户将从浏览器中点击操作
http://localhost:8080/prjcr/pad.action?userid=p02585@test.org
在操作类中,我使用 p02585@test.org 请求参数从 Web 服务检索值列表,并将它们存储在 session 中,如下所示:
//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部分作为 session key
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);
然后将关联的值列表推送到 session 中
ActionContext.getContext().getSession().put(userid, qdList);
并转发到在选择下拉列表中显示此列表的 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>
我尝试使用动态 session key (即用户 ID)从 jsp 中的 session 中提取 qdList。 在java中,我们将其作为session.get(userid)来执行。我还无法理解 OGNL 符号。所以,我不知道如何在 Struts2/OGNL 中做到这一点。
提前致谢
最佳答案
如果你做了
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);
关于java - Struts2 - 使用另一个 session 对象作为键检索 session 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10758518/