Tree presentation of superior-subordinate relationships-Use of jquery + ztree + JSON

Source: Internet
Author: User

This article presents background data in the form of a tree after processing fastjson.

:


It adopts the open-source ztree technology. For details, refer:

Http://www.oschina.net/p/ztree
Because the ztree format supports JSON, we create a node class [treenode. Java]

/*** Treenode. java * copyright (c) 2012 * created: cuiran 15:37:40 */package COM. fastjson. test;/*** todo * @ author cuiran * @ version todo */public class treenode {private integer ID; private integer PID; private string name; private Boolean checked; private Boolean open;/*** @ return the ID */Public integer GETID () {return ID ;} /*** @ Param ID the ID to set */Public void setid (integer ID) {This. id = ID;}/*** @ return the PID */Public integer getpid () {return PID ;} /*** @ Param ID the PID to set */Public void setpid (integer ID) {pid = ID ;} /*** @ return the name */Public String getname () {return name;}/*** @ Param name the name to set */Public void setname (string name) {This. name = Name;}/*** @ return the checked */Public Boolean ischecked () {return checked ;} /*** @ Param checked the checked to set */Public void setchecked (Boolean checked) {This. checked = checked;}/*** @ return the open */Public Boolean isopen () {return open ;} /*** @ Param open the open to set */Public void setopen (Boolean open) {This. open = open;} public treenode (integer ID, integer PID, string name, Boolean checked, Boolean open) {super (); this. id = ID; this. PID = PID; this. name = Name; this. checked = checked; this. open = open;} public treenode () {super ();}}

Create a treeservlet [treeservlet. Java]

Package COM. fastjson. test; import Java. io. ioexception; import Java. io. printwriter; import Java. util. arraylist; import Java. util. list; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import COM. alibaba. fastjson. JSON; public class treeservlet extends httpservlet {/*** constructor of the object. */Public treeservlet () {super () ;}/ *** destruction of the servlet. <br> */Public void destroy () {super. destroy (); // just puts "Destroy" string in log // put your code here}/*** the doget method of the servlet. <br> ** this method is called when a form has its tag Value Method equals to get. ** @ Param request the request send by the client to the server * @ Param response the response send by the server to the client * @ throws servletexception if an error occurred * @ throws ioexception if an error occurred */Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {This. dopost (request, response);}/*** the dopost method of the servlet. <br> ** this method is called when a form has its tag Value Method equals to post. ** @ Param request the request send by the client to the server * @ Param response the response send by the server to the client * @ throws servletexception if an error occurred * @ throws ioexception if an error occurred */Public void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {response. setcontenttype ("text/html"); response. setcharacterencoding ("UTF-8"); printwriter out = response. getwriter (); treenode node1 = new treenode (, "Beijing", false, true); treenode node2 = new treenode (, "Chaoyang District", false, true ); treenode node3 = new treenode (3,1, "Haidian District", false, true); treenode node4 = new treenode (4,0, "Hubei Province", false, true ); treenode node5 = new treenode (5, 4, "Wuhan City", false, true); treenode node6 = new treenode (6, 4, "Xiangyang City", false, true ); list <treenode> List = new arraylist <treenode> (); list. add (node1); list. add (node2); list. add (node3); list. add (node4); list. add (node5); list. add (node6); string jsonstring = JSON. tojsonstring (list); system. out. println ("Call Background:" + jsonstring); out. println (jsonstring); out. flush (); out. close ();}/*** initialization of the servlet. <br> ** @ throws servletexception if an error occurs */Public void Init () throws servletexception {// put your code here }}

Webpage code [tree. jsp]

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 


: Http://vdisk.weibo.com/s/bVYEF

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.