目标:
从数据库层级表:
到目录树结构的实现全过程:
中间产生的JSON数据:
实现途径:
配置jdbc数据源,从数据库中读取以上的层级表,将所有的记录存到ArrayList中,利用fastJson将其解析成JSON数据格式(序列化),而后利用ztree生成目录树结构。
工具版本:
fastJson1.1.9, ztree3.5, jdk1.7, struts1.2, jquery1.4, oracle9i
实现步骤:
index.jsp(访问http://localhost:8088/fastjson/index.jsp)
<%@ page language="java"import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma" content="no-cache">
<metahttp-equiv="cache-control" content="no-cache">
<metahttp-equiv="expires" content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description" content="This is my page">
<!--
<linkrel="stylesheet" type="text/css"href="styles.css">
-->
</head>
<body>
<%
response.sendRedirect("getJson.do");
%>
</body>
</html>
GetJsonAction.java(ActionServlet)
package com.nns.struts.action;
importjavax.servlet.http.HttpServletRequest;
importcom.nns.util.Menu;
importcom.alibaba.fastjson.*;
importjava.util.ArrayList;
importjava.util.List;
importjavax.servlet.http.HttpServletResponse;
importorg.a