In this case, jquery's tree plugin is used, which can be downloaded in the attachment of this article.
JSP Code:
<%@ page language= "java" import= "java.util.*" pageencoding= "Iso-8859-1"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<base href= "<%=basePath%>" >
<title>jquery Tree </title>
<link rel= "stylesheet" href= "Css/tree/jquery.treeview.css"/>
<link rel= "stylesheet" href= "Css/tree/red-treeview.css"/>
<link rel= "stylesheet" href= "Css/tree/screen.css"/>
<script type= "Text/javascript" src= "Js/jquery.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.cookie.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.treeview.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.treeview.async.js" ></script>
<script type= "Text/javascript" >
function Inittrees () {
$ ("#mixed"). TreeView ({
URL: "Tree",
Ajax: {
Data: {
"Additional": function () {
Return "Yeah:" + new Date;
}
},
Type: "POST"
}
});
}
$ (document). Ready (function () {
Inittrees ();
$ ("#refresh"). Click (function () {
$ ("#mixed"). empty ();
Inittrees ();
});
});
</script>
<body>
<ul id= "Mixed" >
</ul>
<button id= "Refresh" >refresh both trees</button>
</body>
=-=====================
Java code: I'm using a servlet.
Package com;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
public class Tree extends HttpServlet {
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
This.dopost (request, response);
}
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Response.setcontenttype ("Text/plain");
Response.setcharacterencoding ("UTF-8");
PrintWriter out = Response.getwriter ();
String re = "[{' Text ': ' Root ', ' expanded ': false, ' children ': [{' Text ': ' 1.1 jquery core '},{' text ': ' 1.2 my JQuery Tree '}]}" +
", {' text ': ' 2 hhh '},{' text ': ' 3 xxx '}]";
Out.flush ();
System.out.println (re);
Out.write (re);
Out.close ();
}
}