Simple usage of ztree v3.x asynchronous loading, ztreev3.x asynchronous loading

Source: Internet
Author: User

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:





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.