mysql - Showing a file tree with parent relation with data from a sql query -




i'm working on final project university, unfortunately stopped in part, because tried several things trying pass variable list inside servlet jsp file use in json function project https://gist.github.com/smrchy/7040377 , render tree.

right project render directly sql query not ordered , don't show relationship. right now created constructor create array or list values , parameters in java class, when try send through session or parameter doesn't work...

protected void doget(httpservletrequest request, httpservletresponse response)     throws servletexception, ioexception { httpsession sessao = request.getsession(false); response.setcontenttype("application/json");  try {     ficheirodao x = new ficheirodao();     x.imprime();     list<ficheiro> lista = x.getlista();      jsonobject json;     jsonarray addresse = new jsonarray();     jsonobject listas = new jsonobject();;     try {         (int = 0; < lista.size(); i++) {             json = new jsonobject();             json.put("id", lista.get(i).getid());             json.put("parentid", lista.get(i).getpasta());             json.put("name", lista.get(i).getnome());                                 addresse.put(i, json);         }     } catch (jsonexception jse) {     }     string s = addresse.tostring();      request.setattribute("listagem", s);     sessao.setattribute("listagem", s);     sessao.setattribute("teste", "post");     request.setattribute("teste", "post");     request.getrequestdispatcher("files.jsp").forward(request, response); 

my sql engine mysql , image showing table of files on comment id_pasta it's parent of file

so stopped trying way , right i'm trying run select in jsp using java jstl create array.

so need experts know best way , easier show correctly pretend. many , regards!

edited more info:

the way want show

  • one
    • two
      • four
    • three
    • five
      • six

so in way can display in easy way want...

edited: failed try save information result set query, ideas?

               class.forname("com.mysql.jdbc.driver");             connection con = drivermanager.getconnection("jdbc:mysql://192.168.1.98:3306/repual", "admin", "123");             statement st = con.createstatement();             resultset rs = st.executequery("select id_fich, nome_fich, tipo_fich, id_pasta repual.ficheiro join repual.permissoes (id_fich=id_ficheiro) , (id_utilizador='26' or dep ('%'+'1'+'%')) , id_pasta!=2 order nome_fich");              gson gson = new gson();             map<string, string> objeto = new hashmap<string, string>();             arraylist data = new arraylist();              while (rs.next())              {                 map<string, string> lv = new hashmap<string, string>();                 lv.put("id", rs.getstring("id_fich"));                 lv.put("parentid", rs.getstring("id_pasta"));                 lv.put("name", rs.getstring("nome_fich"));                 data.add(lv);                 }              //create 'datamap' map object make complete fc datasource.              map<string, string> datamap = new linkedhashmap<string, string>();   /*     gson.tojson() data retrieve string containing     json representation of data in array. */             jsonobject object = new jsonobject();             string json = gson.tojson(data);               con.close(); 

new update:

i changed way do, , i'm trying new way unfortunately can't array "scriptlet" javascript use in methods created.

here code, can me how can use json array in json code (javascript)? created variable status receive array no luck testing string sd receive value, idea use the array "arr" created resultset replace array "sqlquery" manually created in javascript , use functions output elements..

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <%@page import="org.json.jsonexception"%>  <%@page import="org.json.jsonarray"%>  <%@page import="org.json.jsonobject"%>  <%@page import="java.sql.*" %>  <%@page import="java.util.*" %>  <%@page import="com.google.gson.*" %>    <%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>  <%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix = "sql"%>    <%@page contenttype="text/html" pageencoding="utf-8"%>  <%          httpsession sessao = request.getsession(false);      %>  <!doctype html>  <html>      <head>          <meta http-equiv="content-type" content="text/html; charset=utf-8">          <title>jsp page</title>      </head>      <body>    <%                  string myvar = "sadsa";                  class.forname("com.mysql.jdbc.driver");                  connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/repual", "root", "admin");                  statement st = con.createstatement();                  resultset rs = st.executequery("select id_fich, nome_fich, tipo_fich, id_pasta repual.ficheiro join repual.permissoes (id_fich=id_ficheiro) , (id_utilizador='26' or dep ('%'+'1'+'%')) , id_pasta!=2 order nome_fich");                                    gson gson = new gson();                                    jsonarray arr = new jsonarray();                                  while (rs.next())                   {                      jsonobject obj = new jsonobject();                      obj.put("id", rs.getstring("id_fich"));                      obj.put("parentid", rs.getstring("id_pasta"));                      obj.put("name", rs.getstring("nome_fich"));                      arr.put(obj);                      }                     con.close();                  st.close();                  out.println(arr.tostring());                  string sd = "asdsad";             %>           <h1>sql query tree</h1>            <h3>the sql query</h3>          select id_fich, nome_fich, tipo_fich, id_pasta ficheiro join permissoes (id_fich = id_ficheiro) , (id_utilizador = '26' or dep ('%' + '1' + '%')) , id_pasta != 2 order nome_fich          <pre id="sqlquery"></pre>              <h3>the sorted query</h3>          <pre id="sortedquery"></pre>            <h3>the tree</h3>          <pre id="tree"></pre>            <h3>html list</h3>          <div id="htmllist"></div>                    <button type="button" onclick="downloadficheiro();">sadsaad</button>          <button type="button" onclick="downloadficheir();">post</button>                    <!-- jquery 3 -->          <script src="bower_components/jquery/dist/jquery.min.js"></script>      </body>  </html>    <script type="text/javascript">      var _querytreesort = function (options) {          var cfi, e, i, id, o, pid, rfi, ri, thisid, _i, _j, _len, _len1, _ref, _ref1;          id = options.id || "id";          pid = options.parentid || "parentid";          ri = [];          rfi = {};          cfi = {};          o = [];          _ref = options.q;          (i = _i = 0, _len = _ref.length; _i < _len; = ++_i) {              e = _ref[i];              rfi[e[id]] = i;              if (cfi[e[pid]] == null) {                  cfi[e[pid]] = [];              }              cfi[e[pid]].push(options.q[i][id]);          }          _ref1 = options.q;          (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {              e = _ref1[_j];              if (rfi[e[pid]] == null) {                  ri.push(e[id]);              }          }          while (ri.length) {              thisid = ri.splice(0, 1);              o.push(options.q[rfi[thisid]]);              if (cfi[thisid] != null) {                  ri = cfi[thisid].concat(ri);              }          }          return o;      };        var _maketree = function (options) {          var children, e, id, o, pid, temp, _i, _len, _ref;          id = options.id || "id";          pid = options.parentid || "parentid";          children = options.children || "children";          temp = {};          o = [];          _ref = options.q;          (_i = 0, _len = _ref.length; _i < _len; _i++) {              e = _ref[_i];              e[children] = [];              temp[e[id]] = e;              if (temp[e[pid]] != null) {                  temp[e[pid]][children].push(e);              } else {                  o.push(e);              }          }          return o;      };        var _rendertree = function (tree) {          var e, html, _i, _len;          html = "<ul>";          (_i = 0, _len = tree.length; _i < _len; _i++) {              e = tree[_i];              html += "<li>" + e.name;              if (e.children != null) {                  html += _rendertree(e.children);              }              html += "</li>";          }          html += "</ul>";          return html;      };        sqlquery = ([          {"id": "456", "parentid": "123", "name": "dogs"},          {"id": 214, "parentid": 456, "name": "labradors"},          {"id": 123, "parentid": 0, "name": "mammals"},          {"id": 810, "parentid": 456, "name": "pugs"},          {"id": 919, "parentid": 456, "name": "terriers"}      ]);            var status = document.getelementsbyname("arr");                  $('#sqlquery').html(json.stringify(sqlquery, true, 2));             sortedquery = _querytreesort({q: sqlquery})      $('#sortedquery').html(json.stringify(sortedquery, true, 2));                  tree = _maketree({q: sortedquery})      $('#tree').html(json.stringify(tree, true, 2));      htmllist = _rendertree(tree)      $('#htmllist').html(htmllist);                function downloadficheir() { // eliminar uma pasta ou ficheiro          var f = document.form;          f.method = "post";          f.action = 'listaficheiro                            ';          f.submit();      }          function downloadficheiro() { // eliminar uma pasta ou ficheiro          var f = document.form;          f.method = "get";          f.action = 'abreficheiro';          f.submit();      }      foo();            function foo()      {          var value = $('#sd').val();          alert(value);      }  </script>





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -