Pass Arraylist from Java class and fetch it in JSP page In Struts 2

杀马特。学长 韩版系。学妹 提交于 2019-12-02 07:42:28

The iterator tag expects a myList, so you should provide a getter

public List<Coordinates> getMyList() {
    return myList;
}

This value should be initialized like you did

private List<Coordinates> myList = new ArrayList<>();

Then you should not override it in the action, just create a local variable or rename a variable returned by the service.

List<Coordinates> list = lev.getCurrentLocation();
if (list != null && list.size() > 0)
  myList = list;

In the JSP you can get the values from the iterator tag, it finds all values referenced inside the body of the tag in the value stack. You don't need to provide an indexed expression to get the values.

<table>
<s:iterator value="myList">           
<tr>
<td><s:property value="%{latitude}" /></td>
<td><s:property value="%{longitude}" /></td>
</tr>
</s:iterator> 
</table>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!