JQuery Dynamic Loading Tree

Source: Internet
Author: User

In this case, jquery's tree plugin is used, which can be downloaded in the attachment of this article.

JSP Code:

<%@ 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" >
<base href= "<%=basePath%>" >
<title>jquery Tree </title>
<link rel= "stylesheet" href= "Css/tree/jquery.treeview.css"/>
<link rel= "stylesheet" href= "Css/tree/red-treeview.css"/>
<link rel= "stylesheet" href= "Css/tree/screen.css"/>



<script type= "Text/javascript" src= "Js/jquery.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.cookie.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.treeview.js" ></script>
<script type= "Text/javascript" src= "Js/tree/jquery.treeview.async.js" ></script>

<script type= "Text/javascript" >

function Inittrees () {
$ ("#mixed"). TreeView ({
URL: "Tree",
Ajax: {
Data: {
"Additional": function () {
Return "Yeah:" + new Date;
}
},
Type: "POST"
}
});
}
$ (document). Ready (function () {
Inittrees ();

$ ("#refresh"). Click (function () {
$ ("#mixed"). empty ();
Inittrees ();
});
});

</script>


<body>
<ul id= "Mixed" >

</ul>

<button id= "Refresh" >refresh both trees</button>

</body>
=-=====================

Java code: I'm using a servlet.

Package com;

Import java.io.IOException;
Import Java.io.PrintWriter;

Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;

public class Tree extends HttpServlet {

public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {

This.dopost (request, response);
}

public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {

Response.setcontenttype ("Text/plain");
Response.setcharacterencoding ("UTF-8");
PrintWriter out = Response.getwriter ();
String re = "[{' Text ': ' Root ', ' expanded ': false, ' children ': [{' Text ': ' 1.1 jquery core '},{' text ': ' 1.2 my JQuery Tree '}]}" +
", {' text ': ' 2 hhh '},{' text ': ' 3 xxx '}]";
Out.flush ();
System.out.println (re);
Out.write (re);
Out.close ();
}

}

    • Jquery.rar (53.6 KB)

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.