1

我试图在会话中存储一个数组列表,如下所示:

private Map session = ActionContext.getContext().getSession();

数组列表如下所示:

private ArrayList<Integer> numbersEntered = new ArrayList<Integer>();

如果数组列表在会话中尚不存在,则会添加它,但我在将新数据添加到数组列表并使用该数据更新会话时遇到问题。所以 - 我的问题是如何获取会话中已经存在的内容,临时存储它,根据用户输入添加到它并重新添加到会话中?

if ( !session.containsKey(arrayListID) ) 
{
// Place the number the user entered into the session
session.put(arrayListID, numbersEntered);
} else {

// Retrieve session data
 }

我检索了最初存储的内容并将其放在一个字符串中,但因为它是一个数组列表,所以它的存储方式如下:[12]。我不想转换它或拆分字符串...如果您需要更多信息,请告诉我。

干杯

4

1 回答 1

2
if ( !session.containsKey(arrayListID) ) 
{
// Place the number the user entered into the session
session.put(arrayListID, numbersEntered);
} else {
    ArrayList<Integer> list = (ArrayList<Integer>) session.get(arrayListID);
     list.add( 1 /* what you want */);
// Retrieve session data
 }
于 2012-12-12T16:00:48.923 回答