By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

Can you use c:forEach loop to display output of multiple arrays?

P: 24
Hi,
I have been learning JSP and Servlets when I came upon JSTL and EL concepts.. I am new to JSP...
From what I understand JSTL and EL was introduced in JSP so as to avoid using scriplets
Expand|Select|Wrap|Line Numbers
  1. <%%>
in JSP because it clutters everything(business logic as well as presentation logic) in a JSP,which was originally designed for presentation purposes...

But the prefix:forEach loop has me confused...I have tried using it to display arrays,lists,string,arraylists,vectors,etc... for practice and noticed that I have to use
Expand|Select|Wrap|Line Numbers
  1. <prefix:forEach>//Display here//${data}</prefix:forEach>
for every new array,string...
So if I have 10 different arraylists..I will have to use 10 forEach loops...It kind of makes the page too long and lot of efforts...If I use scriplets
Expand|Select|Wrap|Line Numbers
  1. <%%>
I can use a normal for loop and use the
Expand|Select|Wrap|Line Numbers
  1. name.get(variable of for loop);
and get data of all 10 arraylists...

Or is there a way to make prefix:forEach to behave like a normal for loop and get all 10 arraylists's data using single forEach??
Jun 6 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Use object oriented design with POJOs rather than having ten array lists. Then you only have one ArrayList<YourPOJOClass>.
Jun 11 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.