tags:

views:

786

answers:

2

My JSP receives an ArrayList of beans from a Struts2 action.

I want to iterate over them and print every bean and its properties per line.

How can I do this using Struts2 tags?

A: 

Using JSTL:

<c:forEach items="${list}" var="item">
    <c:out value="${item.property}" />
</c:forEach>

You will have to add JSTL to the classpath, because it isn't shipped with Struts, but it shoul work. Of course, using struts' own tag (as shown by BalusC) is a better option.

Bozho
Im using struts2 .
lakshmanan
@lakshmanan I don't think there is a problem to use JSTL with struts2
Bozho
+3  A: 

Use <s:iterator> tag.

<s:iterator value="beans">
     <p>Property foo: <s:property name="foo" /></p>
     <p>Property bar: <s:property name="bar" /></p>
</s:iterator>

An overview of all tags can be found in their own documentation: tag reference. Bookmark it.

BalusC