aman0711
asked on
JSTL for loop
Hi Experts,
I have three arraylists with String elements. All three ArrayLists are in page scope namely:
applications, aspects, groups
On my jsp page I have 3 lists <li> with anchor tags(Code below), Now I want to populate these three <li>'s lists with the contents of my ArrayLists. how do I do that?
#################### HTML CODE ########################## ##
<tr>
<td class="groups">
<ul>
<li><a href="#">AAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
</ul>
</td>
<td class="applications">
<ul>
<li><a href="#">XYZ</a></li>
<li><a href="#">HJK</a></li>
<li><a href="#">KOP</a></li>
<li><a href="#">ILP</a></li>
<li><a href="#">TDF</a></li>
<li><a href="#">DEI</a></li>
</ul>
</td>
<td class="aspects">
<ul>
<li><a href="#">Ava</a></li>
<li><a href="#">Hardware</a></li>
<li><a href="#">Perf</a></li>
<li><a href="#">Trouble</a></li>
<li><a href="#">Trans</a></li>
</ul>
</td>
</tr>
I have three arraylists with String elements. All three ArrayLists are in page scope namely:
applications, aspects, groups
On my jsp page I have 3 lists <li> with anchor tags(Code below), Now I want to populate these three <li>'s lists with the contents of my ArrayLists. how do I do that?
#################### HTML CODE ##########################
<tr>
<td class="groups">
<ul>
<li><a href="#">AAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
</ul>
</td>
<td class="applications">
<ul>
<li><a href="#">XYZ</a></li>
<li><a href="#">HJK</a></li>
<li><a href="#">KOP</a></li>
<li><a href="#">ILP</a></li>
<li><a href="#">TDF</a></li>
<li><a href="#">DEI</a></li>
</ul>
</td>
<td class="aspects">
<ul>
<li><a href="#">Ava</a></li>
<li><a href="#">Hardware</a></li>
<li><a href="#">Perf</a></li>
<li><a href="#">Trouble</a></li>
<li><a href="#">Trans</a></li>
</ul>
</td>
</tr>
can u bit clear??
ASKER
Hi dravid..
I want to populate these HTML <a> links with the content of my Arraylists.
Like ArrayList "groups" has 3 Strings: AAA, BBB, CCC
so this piece of code:
<tr>
<td class="groups">
<ul>
<li><a href="#">AAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
</ul>
</td>
should get values from the ArrayList variable groups. Right now its hardcoded HTML
I want to populate these HTML <a> links with the content of my Arraylists.
Like ArrayList "groups" has 3 Strings: AAA, BBB, CCC
so this piece of code:
<tr>
<td class="groups">
<ul>
<li><a href="#">AAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
</ul>
</td>
should get values from the ArrayList variable groups. Right now its hardcoded HTML
where u get the a href value or is it still # only
ASKER
It should be same as the content inside the TAG.
For example:
<li><a href="AAA">AAA</a></li>
Dravid please help me out with this :)
For example:
<li><a href="AAA">AAA</a></li>
Dravid please help me out with this :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks dravid,
this will surely work.
Can you see what is wrong with this piece of code? This method gets the applications from the DB. I am getting a nullpointerexception.
this will surely work.
Can you see what is wrong with this piece of code? This method gets the applications from the DB. I am getting a nullpointerexception.
public ArrayList getApplication() throws SQLException{
DbJDBC db = new DbJDBC();
Connection conn = db.getConnection();
String sql = "SELECT APPLICATIONS FROM VSLAND.SIWEB_HOME_TAB";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
applications.add(rs.getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
rs.close();
stmt.close();
conn.close();
return applications;
}
where u define application list ??
i think rs.getString(1) this is the pblm check that ?
i think rs.getString(1) this is the pblm check that ?
jsut print be4 adding!1
ASKER
Ok.. give me 2 mins
ASKER
Hey dravid,
I fixed that... but output is little weird. I guess we need to break the loop?
jstl-snap.PNG
I fixed that... but output is little weird. I guess we need to break the loop?
jstl-snap.PNG
is it infinity loop???
<ul>
<c:forEach var="groups" items="${groups}">
<li><a href="<c:out value='${groups}'/>"><c:ou t value='${groups}'/></a></l i>
</c:forEach>
</ul>
<c:forEach var="groups" items="${groups}">
<li><a href="<c:out value='${groups}'/>"><c:ou
</c:forEach>
</ul>
<c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
if u know the size u directly give here!!
if u know the size u directly give here!!
i think DB retrive value have the issue!!!
we will meet 2morrow gd nite...
ASKER
Hi Dravid,
still no difference.
Why is it printing the whole array list at the bottom
still no difference.
Why is it printing the whole array list at the bottom
ASKER
Thanks for the help :)
try this:
<c:forEach var="group" items="${groups}">
<a href="${group}">${group}</a>
</c:forEach>
ASKER
Thanks man