Simple usage of jquery easyui tree asynchronous loading

Source: Internet
Author: User

Simple usage of jquery easyui tree asynchronous loading

Jsp page:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page
 
 
     
 
 
 
     
     
     <script type="text/javascript" src="jquery/easyui/jquery.min.js"></script>    <script type="text/javascript" src="jquery/easyui/jquery.easyui.min.js"></script>    <script type="text/javascript">  function ok(){$("#file_tree").tree({url:'TestTreeServlet',lines:true,onClick:function(node){if(node.type=="file"){ var ps={"id":node.id}; $.post("ReadFileServlet",ps,function(data){ alert(data); $("#info").empty().append(data); });}}});  }    </script>        This is my JSP page. 

    Background code:

    Tree menu-display the file list by path

    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. google. gson. jsonArray; import util. TreeJson; public class TestTreeServlet 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"); if (id = null | "". equals (id) {id = "E:/test/";} 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) {for (int I = 0; I
     
      
    0) {// There is a sub-file map. put ("state", "closed");} else {map. put ("state", "open");} map. put ("iconCls", file. isFile () = true? "Icon-file": "icon-folder"); map. put ("type", file. isFile () = true? "File": "folder"); list. add (map) ;}} System. out. println (list. toString (); return list ;}}
     

    Read File Content

    Package servlet; import java. io. bufferedReader; import java. io. file; import java. io. fileReader; import java. io. IOException; import java. io. inputStream; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; public class ReadFileServlet extends HttpServlet {@ Overrideprotected void service (HttpSe RvletRequest request, HttpServletResponse response) throws ServletException, IOException {response. setCharacterEncoding ("UTF-8"); response. setContentType ("text/html"); String fileName = request. getParameter ("id"); File file = new File (fileName); BufferedReader reader = null; StringBuffer text = new StringBuffer (""); try {reader = new BufferedReader (new FileReader (file); int line = 1; String tempString = n Ull; // read a row at a time until null is the end of the file while (tempString = reader. readLine ())! = Null) {// display the row number System. out. println (line + ":" + tempString); text. append (tempString + "\ n"); line ++;} reader. close ();} catch (IOException e) {e. printStackTrace ();} finally {if (reader! = Null) {try {reader. close () ;}catch (IOException e1) {}} response. getWriter (). write (text. toString ());}}




    Page effect display:













    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.