使用JSTL forEach迭代ArrayList项 [英] Iterating over ArrayList items with JSTL forEach

查看:244
本文介绍了使用JSTL forEach迭代ArrayList项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行ArrayList项目时遇到问题并在JSP文件中显示它们。

I'm having problem running over ArrayList items and displaying them in JSP file.

这是我的bean:

public class UsersList {
    private ArrayList<UserDetails> users = new ArrayList<UserDetails>();

    public ArrayList getUsers(  ){
        return users;
    }

    public void setUsers(ArrayList<UserDetails> users){
        this.users = users;
    }
}

用户包含UserDetails,它只是具有3个String属性的类:电子邮件,用户名,密码

users contains UserDetails which is simply class with 3 String properties: email, username, password

现在我试图在表格中显示详细信息..首先在index.jsp中我有这些命令:

Now I am trying to display the details in a table.. first in index.jsp I have those commands:

            UsersList bean = new UsersList();
            bean.setUsers(db.getUsersList()); // getting all user deatils from database into the list
            session.setAttribute("bean", bean);

            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/adminPage.jsp");
            dispatcher.forward(request, response);

现在在adminPage.jsp上,当我应该显示包含用户详细信息的表时,它什么都不显示。以下是代码:

And now on adminPage.jsp when I should display the table containing the users details, its displays nothing. Here is the code:

<c:forEach var="current" items="${bean.users}" >
<tr>
    <td>${current.email}</td>
    <td>${current.username}</td>
    <td><input type="checkbox" name="delete" value="${current.email}"</td>
</tr>
 </c:forEach>

知道这里有什么问题吗?谢谢。

Any idea what's the problem here?? Thanks.

推荐答案

检查你的前缀c是否指向正确的标签库。

Check if your prefix "c" points to the right tag library.

它应该是


http://java.sun.com/jsp/jstl/core

"http://java.sun.com/jsp/jstl/core"

如果这不起作用,请检查填充数据的逻辑是否有错误。

If that does not work, check if there is mistake in the logic of populating the data.

这篇关于使用JSTL forEach迭代ArrayList项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆