简体   繁体   English

如何使用struts2 ognl标签将会话中的arraylist迭代到jsp

[英]how to iterate a arraylist from session into jsp using struts2 ognl tags

I have a class where I am creating a non empty ArrayList and putting it is not a session. 我有一个类,我在其中创建一个非空的ArrayList并将其放置为非会话。 Now, I want to iterate that list which kept in session into my JSP page. 现在,我想遍历会话的列表到我的JSP页面。

I tried it but nothing is coming. 我试过了,但是什么都没有。

in action class 动作课

..................
books = new ArrayList<Bookdetails>();
session.put(BillTransactionBooksConstants.BOK, books);
return SUCCUSS;

Note : I tested my list is not empty and it is correctly adding into session. 注意:我测试了我的列表不为空,并且已正确添加到会话中。 My only problem is how can I show this list into my JSP from session. 我唯一的问题是如何从会话将列表显示到我的JSP中。

BillTransactionBooksConstants : BillTransactionBooksConstants

package v.esoft.actions.booktransaction; 
public class BillTransactionBooksConstants 
{
    public static final String BOK = "BOK"; 
}

shortbill.jsp : shortbill.jsp

<s:iterator value="#session.BillTransactionBooksConstants.BOK" status="userStatus">
    <s:property value="Bookdetails.bookTitile" />
    <br/>
</s:iterator>

Refer only to the property name, and use the constant value directly: 仅引用属性名称,并直接使用常量值:

<s:iterator value="#session.BOK">
    <s:property value="bookTitle" />
    <br/>
</s:iterator>

Note that I've corrected the spelling of the property. 请注意,我已更正了该属性的拼写。

Also note that "SUCCESS" is spelled "SUCCESS", not "SUCCUSS". 另请注意,“ SUCCESS”拼写为“ SUCCESS”,而不是“ SUCCUSS”。

If you wish to use the constant name you should be able to use the following, but I didn't test it: 如果您希望使用常量名称,则应该可以使用以下名称,但我并未对其进行测试:

<s:iterator value="#session[@v.esoft.actions.booktransaction.BillTransactionBooksConstants@BOK]">

Assuming static member access is enabled. 假设启用了静态成员访问。

Try this 尝试这个

<s:iterator value="#session.BOK" status="userStatus">
<tr class="<s:if test="%{#userStatus.odd == true} ">odd</s:if> <s:else>even</s:else>">
<td><s:property value="bookTitile" /></td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM