【发布时间】:2014-06-16 14:56:41
【问题描述】:
我是JSP & JSTL 的新手,我有一个如下的 json 数组:
[ { "id" : 1, "name" : "A" }, { "id" : 2, "name" : "b" }]
我需要在 HTML 表格视图中打印。
我试过用here说的代码
<table>
<c:forEach items="${persons}" var="person">
<tr>
<td>${person.name}</td>
</tr>
</c:forEach>
</table>
但是我收到了这个错误
javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String
有人纠正我哪里出错了。
【问题讨论】:
-
json 转换成人员列表了吗?并且该列表仅在 html 页面中使用?
-
显示你的打印 HTML 表格方法。
-
@bigGuy 这是我用的。
${person.name} -
@Parthi04 - 那么您希望 JSTL 如何工作?如果您向 JSTL 提供这样的 json 字符串,它显然无法找到其中包含名称字段/属性的对象。将您的 json 解析为人员对象列表并在 JSTL 中使用它
-
我打赌你没有从 eexample 复制这一行: List
persons = new Gson().fromJson(jsonPersons, new TypeToken - >() {}.getType()) ;