File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes using <html:iterate> to display an array in the array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using <html:iterate> to display an array in the array" Watch "using <html:iterate> to display an array in the array" New topic

using <html:iterate> to display an array in the array

david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133

The jsp file get an array groupA from session which has the structure like this:

I want to display the elements of groupB[] in a table, in stead of using jsp script, I am wondering if I can use <html:iterate> to accomplish this?

Thanks for the help!
Ankit Garg

Joined: Aug 03, 2008
Posts: 9374

I think you need to post your code properly. The code that you gave won't compile as groupB is not declared when it is used in groupA. Also you can't fit a String[] into a String[]. You need to have a 2-d String array. Are you trying to say that you want to iterate over a 2 dimensional array like this

If yes, then I think you can easily do this in Struts 2 (I don't know about struts 1 and you have also not mentioned which version of struts you are using)...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
Thank you Ankit Garg. sorry i did not explain clearly, i am using struts 1.2.9. I have a ActionForm like the following:

In JSP file, there is dropdown list which contains all group names and shows the first one. Now I want to add a table to display the student names in a group when user select a group
from a dropdown list. And user may move students to other table, then I need update the table in form and forward to Action. Could I use Struts <html:iterate> to do this? I know how to use <html:iterate> to display like uid, name, but do not know how to display students array.

For example, if I have 3 group A,B,C, how could I diplay student names in group B using html:iterate ?

David Newton

Joined: Sep 29, 2008
Posts: 12617

It's <logic:iterate>, not <html:iterate>. I'm not sure what the confusion is--the iterate tag docs describe it pretty well.

That said, using JSTL may be a better solution--it's recommended that when JSTL and Struts tag functionality overlap that JSTL is used. The Struts tags were written before JSTL existed.
Lei Guoguo

Joined: Mar 31, 2009
Posts: 26
if you can use jstl tag, you can write like under code

if not

<%page.setAttribute("groupB", ((Object[])request.getAttribute("groupA"))[3]) %>
<logic:iterator />

I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail:, I will help you, and improve my english. Thanks everyone.
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
Thank you David and Lei!
I agree. Here's the link:
subject: using <html:iterate> to display an array in the array
It's not a secret anymore!