gpt4 book ai didi

java - 使用struts2从jsp页面的隐藏字段获取arraylist到action类

转载 作者:行者123 更新时间:2023-11-30 05:51:13 27 4
gpt4 key购买 nike

我有一个数组列表,我已将其设置到 jsp 的 hiddenField 中。现在我必须在我的操作类中访问此列表。下面,代码片段如下

我的 Action 类

private ArrayList<TXT_File_Action> statusResult_list=new ArrayList<TXT_File_Action>();
private ArrayList<TXT_Beans> regenerateTXTList=new ArrayList<TXT_Beans>();
private ArrayList<TXT_Beans> pagingList=new ArrayList<TXT_Beans>();
private ArrayList<TXT_Beans> serverList=new ArrayList<TXT_Beans>();



public String getGenerateList()
{

for(int j=0;j<customers_accountList.size();j++)
{

dataList=txt_managerInstance.regenerateListData(id_no);
regenerateTXTList.add(dataList.get(0));
}

pagingList=getRegenerateTXTList();
setRegenerateTXTList(getRegenerateTXTList());
setPagingList(getPagingList());

return SUCCESS;
}

getters..n setters

我的 JSP 代码是

 <s:iterator value="pagingList">
<tr>
<td align="center"><s:property value="customerId" /></td>
<td align="center"><s:property value="cspId" /></td>
<td align="center"><s:property value="branchCode" /></td>
<td align="center" id="bcID"><s:property value="bcCode"/></td>
</tr>

</s:iterator>

下面我在 jsp 隐藏字段中设置列表如下:

   <input type="hidden" name="serverList" id="serverList"  value="<s:property value="pagingList"/>"/>

现在,当我点击一个事件时,我希望在我的 Action 类中有这个列表。每当我尝试在我的操作中打印此列表 serverList 的大小时,我都会收到以下错误:

java.lang.ArrayIndexOutOfBoundsException: -1
java.util.ArrayList.get(Unknown Source)
com.alw.action.TXT_File_Action.setPaginationList(TXT_File_Action.java:424)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
.
.
.

但我确定我在这个隐藏字段中获得了所有 Arrayllist 数据,因为我已经在我的页面上检查过了

**<input type="hidden" name="serverList" id="serverList"  value="<s:property value="pagingList"/>"/>**

这是怎么回事,如何在我的操作类中获取此列表。任何帮助都会非常有帮助。

最佳答案

不能将List 或任何Object 直接放入inputs:hidden 中,这里是DOCUMENT ,属性 value 应该是一个字符串。如果你打算这样做,你应该使用 Struts2 Type Conversion .

解决问题的最简单方法是将列表放入 session 中。这是链接 SessionAware .

关于java - 使用struts2从jsp页面的隐藏字段获取arraylist到action类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12976963/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com