Simple usage of ztree v3.x asynchronous loading, ztreev3.x asynchronous loading
Ztree Official Website: http://www.ztree.me/v3/main.php#_zTreeInfo
Page:
<Span style = "font-size: 14px;"> <% @ 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">
Background:
<Span style = "font-size: 14px;"> package servlet; import java. io. file; import java. io. IOException; import java. util. arrayList; import java. util. hashMap; import java. util. list; import java. util. map; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import net. sf. json. JSONArray; // import com. goog Le. gson. jsonArray; import util. treeJson; public class TestzTreeServlet extends HttpServlet {@ Overrideprotected void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request. setCharacterEncoding ("UTF-8"); response. setCharacterEncoding ("UTF-8"); response. setContentType ("text/html"); String id = request. getParameter ("id"); String type = request. getParameter ("Type"); if (id = null | ". equals (id) {id =" E:/test ";}if (type! = Null & type. equals ("edit") {String name = request. getParameter ("name"); String msg = "true"; try {if (name = null | name. trim (). equals ("") {msg = "node name cannot be blank! ";}Editfile (id, name);} catch (Exception e) {msg =" Edit failed: "+ e. getMessage ();} response. getWriter (). write (msg);} else {List list = readPath (id); JSONArray json = JSONArray. fromObject (list); response. getWriter (). write (json. toString () ;}} public static List readPath (String path) {List list = new ArrayList (); File file = new File (path); if (file. exists () {File [] fs = file. listFiles (); if (fs! = Null & fs. length> 0) {// multiple files for (int I = 0; I <fs. length; I ++) {Map map = new HashMap (); map. put ("id", fs [I]. getAbsolutePath (); map. put ("pId", path); map. put ("name", fs [I]. getName (); map. put ("isParent", fs [I]. isFile () = true? "False": "true"); list. add (map) ;}}return list;} public static void editFile (String path, String rename) throws Exception {File file = new File (path); if (file. exists () {String rePath = ""; if (path. contains ("/") {rePath = path. substring (0, path. lastIndexOf ("/") + 1) + rename;} else if (path. contains ("\") {rePath = path. substring (0, path. lastIndexOf ("\") + 1) + rename;} file. renameTo (new File (rePath) ;}}</span>
Effect: