Reputation: 1655
I have a Java Bean as Below
class Account
{
private long id;
private String userName;
private String userId;
//Getters, Setters for Above
}
public List<Account> getAccountList()
{
List<Account> accountList = new ArrayList();
Account account;
.
.
.
//db code for fetching data's from database
while(rs.next())
{
account = new Account();
account.setId(rs.getLong("Id"));
account.setUserName(rs.getString("UserName"));
account.setUserId(rs.getString("UserId"));
accountList.add(account);
}
return accountList ;
}
I am Assigning the List which I got in the function in a servlet and I am forwarding it to JSP page where I will display List of Users in Account.
List<Account> accountList = new ArrayList<Account>();
accountList = objdbUtil.getAccountList();
request.setAttribute("arrUsersList", accountList);
RequestDispatcher rdst = request.getRequestDispatcher("UserList.jsp");
rdst.forward(request, response);
Now how to display the Data's in JSP as the List contains collections in it.
Can I directly use below code
<c:forEach var="arrUsersList" items="${requestScope.arrUsersList}">
</c:forEach>
Upvotes: 0
Views: 7198
Reputation: 9559
You are on the right lines. The forEach tag will iterate through your list of Account objects.
<c:forEach var="account" items="${requestScope.arrUsersList}">
<c:out value="${account.userName}" />
...
</c:forEach>
Upvotes: 1