English 中文(简体)
Struts2-使用另一个会话对象作为关键字检索会话对象
原标题:Struts2 - retrieve session object using another session object as key

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

我的应用程序流程如下:用户将从浏览器中点击操作

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

在操作类中,我使用[email protected]请求参数从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>  

I ve tried to pull the qdList from the session in jsp using a dynamic session key which is the userid. In java, we do it as session.get(userid). I am not able to get in terms with the OGNL notation yet. So, I dont know how to do it in Struts2/OGNL.

提前感谢

问题回答

如果你做一个

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

in your action you will get class org.apache.struts2.dispatcher.SessionMap , but 如果你做一个

out.println(session.getClass());

在jsp中,您将得到org.apache.catalina.session类。StandardSessionFacade或类似的东西(我使用tomcat)

所以试试看

session.getAttribute(userid);

而不是

session.get(userid);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签