[英]How to retrieve a list of Java objects into a jsp file
I'm working on a java-jsp project and I'm having a list of java objects to be displayed in the jsp page.我正在处理一个 java-jsp 项目,并且我有一个要在 jsp 页面中显示的 java 对象列表。 The java line containing the list of those objects is as follows:包含这些对象列表的 java 行如下:
private List<String> derivedNames;
private List<DiffResponse> diffResponses;
private List<String> pRResults;
DiffResponse class is like this: DiffResponse 类是这样的:
private String path;
private List<DiffOutput> diffOutputList;
private boolean isConflict;
In the jsp file when I console.log the diffOutput, it returns pure java object as stated below without showing the content inside.在jsp文件中,当我console.log diffOutput时,它返回纯java对象,如下所述,不显示里面的内容。
org.example.rs.umt.DiffOutput@4d9d8911,
org.example.rs.umt.DiffOutput@3cc6fff7,
org.example.rs.umt.DiffOutput@311bce65,
org.example.rs.umt.DiffOutput@7611bf66,
org.example.rs.umt.DiffOutput@57e575b4,
org.example.rs.umt.DiffOutput@5c5711f8,
Below is the jsp code to retrieve the data:下面是检索数据的jsp代码:
<c:forEach items="${results.diffResponses}" var="diffResponse">
var distributionPath = '<c:out value="${diffResponse.distributionPath}"/>'
console.log("Dist: ",distributionPath);
var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'
console.log(diffOutputList);
</c:forEach>
Here the distributionPath is obtained as expected这里的 distributionPath 是按预期获得的
Well your diffOutputList
is in itself a list.那么你的diffOutputList
本身就是一个列表。 So you have to do a nested <c:forEach>
like this:所以你必须像这样做一个嵌套的<c:forEach>
:
<c:forEach items="${results.diffResponses}" var="diffResponse">
var distributionPath = '<c:out value="${diffResponse.distributionPath}"/>'
console.log("Dist: ",distributionPath);
<c:forEach items="${diffResponse.diffOutputList}" var="diffOutput">
var diffOutput = '<c:out value="${diffOutput.???}"/>'
console.log(diffOutput);
</c:forEach>
</c:forEach>
So if have included ???所以如果包含了??? in the code.在代码中。 There you have to set a field which exists in class DiffOutput.在那里你必须设置一个存在于类 DiffOutput 中的字段。
Another way is to overwrite the .toString()
method in class DiffOutput.另一种方法是覆盖 DiffOutput 类中的.toString()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.