2012-05-25 16 views
3

我是struts2的新手,我尝试使用动态会话键检索会话对象。Struts2 - 使用另一个会话对象作为关键字检索会话对象

我的应用程序流程是这样的:用户将他们的浏览器

http://localhost:8080/prjcr/[email protected] 

在动作类打的动作,我用[email protected]要求PARAM检索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)); 

提取用户ID部分将被用作会话密钥

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:

<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中做到这一点。

在此先感谢

回答

0

,如果你在你的行动做了

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

你会得到 '类org.apache.struts2.dispatcher.SessionMap',但如果你做一个

out.println(session.getClass()); 

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

所以尽量的

session.getAttribute(userid); 

代替

session.get(userid); 
+0

嗨pbaris。感谢您的回复。你的意思是建议像jsP中select标签中的列表属性一样使用下面的属性吗?列表= session.getAttribute(用户ID)。这会工作吗?另外,session.getAttribuet(userid)只会得到我用来获取相应列表的用户标识。像这样:session.getAttribute(session.getAttribute(userid))。我如何在OGNL符号中做到这一点?我想知道,这可能吗?虽然,我不知道,并不意味着它不可能。 – user1417827