Java – displays the tree on the JSP page

I need to display the tree on the JSP page How can I do this? I have the following objects:

public class Node {
    private Long id;
    private Long parentId;
    private String name;
    private List<Node> children;

    // Getters & setters

}

Solution

Use JSP to scroll recursively

In the controller In Java

Node root = getTreeRootNode();
request.setAttribute("node",root);

In main JSP page

<jsp:include page="node.jsp"/>

In node JSP

<c:forEach var="node" items="${node.children}">
    <!-- TODO: print the node here -->
    <c:set var="node" value="${node}" scope="request"/>
    <jsp:include page="node.jsp"/>
</c:forEach>

be based on http://web.archive.org/web/20130509135219/http://blog.boyandi.net/2007/11/21/jsp -recursion/

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>