This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Struts and the fly likes Need Help on How to Iterate Multiple List in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need Help on How to Iterate Multiple List in JSP" Watch "Need Help on How to Iterate Multiple List in JSP" New topic
Author

Need Help on How to Iterate Multiple List in JSP

Piyush Balas
Greenhorn

Joined: May 18, 2013
Posts: 3
Hi,

I have 3 Arraylist built in Java action, List1, List2 and List3.

I am using Struts2 and want to iterate all 3 list at a same time in JSP so can anyone suggest a way on how to do that?

My requirement is

List1 contains Name for exa{AA,BB,CC...}
List2 contains Technology names {Java, JSP, Net...}
List3 contains Expertise {1,2,3,...}

My output will be in JSP should like

Name Technology Expertise
----------------------------------------
AA Java 1
BB JSP 2
CC Net 3

Can anyone help me please?

Thanks in advance.

Piyush
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63227
    
  69

Why do you have such a poor model for your data? If each of these properties describe an element, you should have a bean that abstracts the element. Then you would have one list of the beans, each of which holds the three properties for whatever is being modeled.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

Piyush,
Welcome to CodeRanch!

As Bear points out, you should create a Java object. Then you can use a Struts tag or JSTL to loop through that single list.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Piyush Balas
Greenhorn

Joined: May 18, 2013
Posts: 3
Thanks Bear for quick response.

Do you have such example which i can refer?


Thanks
Piyush
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63227
    
  69

OK, it looks like each item (whatever they are) has a name, a technology, and a numeric level of some sort. Rather than three lists that contains these values separately, define a class that groups them together logically to describe the item. Without more information, I'll simply call the item a zarb. And the Zarb class could be:

Then you have one list of zarbs that gets passed to the JSP for iteration with <c:forEach> (or whatever the heck Struts uses).

The job of a JSP gets infinitely harder when you model data poorly.
Piyush Balas
Greenhorn

Joined: May 18, 2013
Posts: 3
Thanks Bear for your help.


Piyush
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Need Help on How to Iterate Multiple List in JSP
 
It's not a secret anymore!