0

我正在尝试使用 jquery 从操作中获取 arraylist。然后从该数组列表的每一行获取数据。我的代码如下:

我的控制器动作(UserAction.java):

public class UserAction  extends ActionSupport {

private ArrayList<UserVO> listUsers;
public ArrayList<UserVO> getListUsers() {
    return listUsers;
}
public void setListUsers(ArrayList<UserVO> listUsers) {
    this.listUsers = listUsers;
}

public String execute(){

    listUsers = new ArrayList<UserVO>;
    UserVO bean = new UserVO();
    bean.setUserName("john");
    bean.setLastName("mit");
    listUsers.add(bean);

    bean = new UserVO();
    bean.setUserName("Madam");
    bean.setLastName("Git");
    listUsers.add(bean);

    return SUCCESS;
}
}

和用户VO

    public class UserVO  {
         private String userName;
         private Strnig lastName;

         //get, set methods 
             ....
    }

还有我的jsp:

user.jsp
      <script type="text/javascript">
         jQuery(document).ready(function($){

            var objlistUsers = '${listUsers}';  //get all list from action
            for (var i = 0; i < 2; i++) {
                 var aUser = "objlistUsers[test]";

                 var aaa = aUser.replace("test", i);

                 aaa = '${'+aaa+'}';  ///My purpose: I want to get data per row: ${listUsers[i]}            
                 alert(aaa);  //but can not return exactly
          }

        });

      </script>

我想获取列表中每行的数据,例如: ${listUsers[i]} 如何获取它?

谢谢!

4

1 回答 1

0

您可以jstl为此使用标签

   <script>
    <c:forEach var="user" items="${listUsers}">
      alert('${user.userName}');
    </c:forEach>
 </script>

JSTL在使用标签之前使用此导入

 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
于 2013-05-28T02:57:19.477 回答