2012-05-25 18 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