Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use arraylist in jstl

 
nizams uddin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList allBusinessCenterList = new allBusinessCenterList();
allBusinessCenterList.add("1");
allBusinessCenterList.add("12");
allBusinessCenterList.add("13");

how to convert the below code using jstl
assume arraylist a normal list with values and does not contain any bean value.

<% for(int i =0;i <allBusinessCenterList.size();i++){%>
uot.println(allBusinessCenterList.get(i));
<% } %>
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you include this header

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

then your code:

<c:forEach var="businessCenter" items="${allBusinessCenterList}">
${businessCenter}
</c:forEach>
 
nizams uddin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the suggestion.
but i had allready tried that and it was not working, so i posted to the gruop.
i tried with the sample code that you gave but it is still not responding.
i have inserted the tag lib for c


Originally posted by ni ni:
ArrayList allBusinessCenterList = new allBusinessCenterList();
allBusinessCenterList.add("1");
allBusinessCenterList.add("12");
allBusinessCenterList.add("13");

how to convert the below code using jstl
assume arraylist a normal list with values and does not contain any bean value.

<% for(int i =0;i <allBusinessCenterList.size();i++){%>
uot.println(allBusinessCenterList.get(i));
<% } %>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ni ni
Welcome to JavaRanch!

We're pleased to have you here with us in the JSP forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timothy Sam's response was entirely correct.
If its not working for you, then you have a configuration issue.

See the FAQ entry on JSTL: http://faq.javaranch.com/view?ElOrJstlNotWorkingAsExpected

If that does not help you, then reply back with answers to the following questions
- What server are you using (version)
- What version of JSTL are you using
- Any error messages / unexpected output - ie what is WRONG with your page other than "it doesn't work".
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, allBusinessCenterList has to be in one of the following scopes: page, request, session or application.
If the code you've posted is in a scriptlet, you won't be able to access the array, unless you put it in one of the above scopes.

As Stefan said, if you've got an error message, please post it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic