Contact Us
    SearchSearch   RegisterRegister   Log inLog in 

tree view in jsp

tree view in jsp

Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message

Joined: 28 Mar 2007
Posts: 3

PostPosted: Wed Mar 28, 2007 11:54 am    Post subject: tree view in jsp Reply with quote

i want to show data in tree view format, i want to do it without using tag libraries in java, jsp. dont know how it will happened
Back to top
View user's profile Send private message

Joined: 20 Apr 2007
Posts: 4

PostPosted: Fri Apr 20, 2007 1:29 pm    Post subject: tree view in jsp Reply with quote

I want to thanks my friend priya.
you have to do recursive in query whatever ur sql database. i m using this mysql.
i got concept from but they donot provide that source in jsp. i got that code in javabean and old version. then i see in code dot net.That was working fine. And i changed that code in jsp. it is working fine here.



<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.StringTokenizer,java.util.*,java.text.*" errorPage="" %>

             Connection conn =null;
           conn = DriverManager.getConnection("jdbc:mysql://localhost/yourDatabaseName","root","password");
         String tempNodeID=nullconv(request.getParameter("NodeID"));
         int tempdownline=nullIntconv(nullconv(request.getParameter("downline")));
         catch(Exception e)

public String nullconv(String str)
   else if(str.equalsIgnoreCase("null"))
   else if((str.trim()).equals(""))
   return str;
public int nullIntconv(String inv)
      else if((inv.trim()).equals("null"))
      else if(inv.equals(""))
      return Integer.parseInt(inv);

       Connection con=null;   

      PreparedStatement pstmt = null;
      PreparedStatement pstmt1 = null;

      ResultSet rs = null;
      ResultSet rs1 = null;

      JspWriter out=null;
      String   NodeID =  "1";
       int downline = 0;
   public void setConnection(Connection con,JspWriter ot,String rq,int dwline)
          NodeID="1";  ///////////////////// change this according to your requirement
          downline=20;   ////////////////////// this is for advance requirement should use according to your requirement
      catch(Exception e)
         System.out.println("IO error :"+e);
   public void outputJavascriptForRoot()
      String queryString =null;
      queryString ="SELECT NodeID, Name, IsFolder, ParentID, Link, level FROM NodesTable WHERE (NodeID='" + NodeID +"')";
      // It should return one and one only
      while (
        out.print("foldersTree = gFld('<i>tree</i>')" + "\n");
        out.print("web" + rs.getString("NodeID") + " = insFld(foldersTree, gFld('" + rs.getString("Name") + "[" + rs.getString("NodeID") + "]"  + "','tree.jsp?distibutorid=" + rs.getString("NodeID") + "&downline="+downline+"'))" + "\n");
        outputJavascriptForSubFolder(Integer.parseInt(rs.getString("NodeID")), rs.getString("Name"),"web" + rs.getString("NodeID"), rs.getString("Link"), downline);
      // close the DataReader and Connection
      catch(SQLException ex)
        System.out.println("sqll eroror :"+ex);
       catch(Exception e)
          System.out.println("error :"+e);
 public void outputJavascriptForSubFolder(int folderId, String Name, String fName, String Link, int downline)
      PreparedStatement psQueryString = null;
      ResultSet rsqueryString = null;
       String queryString1 ="SELECT NodeID, Name, IsFolder, ParentID, Link FROM NodesTable WHERE ((ParentID=" + folderId + ") AND (IsFolder=1) AND level<=" + downline + ") ORDER BY Name";
      // iterate through the rows in the Nodes table
         out.print("web" + rsqueryString.getString("NodeID") + "=insFld(" + fName + ",gFld('" + rsqueryString.getString("Name") + "[" + rsqueryString.getString("NodeID") + "]','tree.jsp?NodeID="+rsqueryString.getString("NodeID")+"&downline="+downline+"'))  " + "\n" );
         outputJavascriptForSubFolder(Integer.parseInt(rsqueryString.getString("NodeID")),rsqueryString.getString("Name"),"web" + rsqueryString.getString("NodeID"),rsqueryString.getString("Link"),downline);
   catch(Exception e)


<title>Tree from database</title>

<style type="text/css">
   BODY {background-color: white}
   TD {font-size: 10pt;
       font-family: verdana,helvetica;
      text-decoration: none;
   A  {text-decoration: none;
       color: black}

<!-- As in a client-side built tree, all the tree infrastructure is put in place
     within the HEAD block, but the actual tree rendering is trigered within the
     BODY -->

<!-- Code for browser detection -->
<script language="javascript" src="ua.js"></script>
<script language="javascript" src="ftiens4.js"></script>
<!-- Execution of the code that actually builds the specific tree.
     The variable foldersTree creates its structure with calls to
    gFld, insFld, and insDoc -->
<script language="javascript">

// Load a page as if a node on the tree was clicked (synchronize frames)
// (Highlights selection if highlight is available.)
function loadSynchPage(xID)
   var folderObj;
   docObj = parent.treeframe.findObj(xID);

    //Scroll the tree window to show the selected node
    //Other code in these functions needs to be changed to work with
    //frameless pages, but this code should, I think, simply be removed
    if (typeof parent.treeframe.document.body != "undefined") //scroll doesn work with NS4, for example

<body topmargin=16 marginheight=16>

<!-- By removing the follwoing code you are violating your user agreement.
     Corporate users or any others that want to remove the link should check
    the online FAQ for instructions on how to obtain a version without the link -->
<!-- Removing this link will make the script stop from working -->
<div style="position:absolute; top:0; left:0; "><table border=0><tr><td><font size=-2><a style="font-size:7pt;text-decoration:none;color:silver" href="" target=_blank>JavaScript Tree Menu</a></font></td></tr></table></div>

<!-- Build the browser's objects and display default view of the
     tree. -->
<script language="javascript">
//Click the Parakeet link
A tree for site navigation will open here if you enable JavaScript in your browser.

create database

and this table


CREATE TABLE  nodestable (
  `NodeID` int(10) unsigned NOT NULL auto_increment,
  `Name` varchar(45) NOT NULL default '',
  `IsFolder` int(10) unsigned NOT NULL default '0',
  `ParentID` int(10) unsigned NOT NULL default '0',
  `Link` varchar(45) NOT NULL default '',
  `level` int(11) default NULL,

This is for mysql database you can use any one

insert this data record in table


INSERT INTO `nodestable` (`NodeID`,`Name`,`IsFolder`,`ParentID`,`Link`,`level`) VALUES

You can down this Source code of tree in jsp Download

then run this good luck

more reference
Back to top
View user's profile Send private message

Joined: 30 Apr 2007
Posts: 1

PostPosted: Mon Apr 30, 2007 4:50 pm    Post subject: tree view in jsp Reply with quote

This code is working fine in jsp. But today it is time of to switch struts. I want to do tree view in struts. Can you give me solution in struts as this tree as same in jsp
Back to top
View user's profile Send private message

Joined: 28 Mar 2007
Posts: 3

PostPosted: Thu May 10, 2007 5:57 pm    Post subject: jsp tree Reply with quote

i have listen that, we can make tree easily in tag lib in java jsp. this is in built method that do own and draw tree for us. i have studied on internet and find some site on this tree and apache own also have tag lib on tree view hope this will help you. and you will also help me on tree view
Back to top
View user's profile Send private message

Joined: 11 May 2007
Posts: 2

PostPosted: Fri May 11, 2007 4:28 pm    Post subject: tree in jsp Reply with quote

Anyone can give me idea of drawing tree in simple html or javascript. because i can not use server side or any programmering language. :( so i have left only one option. make a tree in html javascript. But i dont have any idea of this. plz help :P
Back to top
View user's profile Send private message

Joined: 16 May 2007
Posts: 1

PostPosted: Wed May 16, 2007 1:14 pm    Post subject: tree in jsp Reply with quote

There many site who provide tree in html and jsp server side.
check out for html tree
this will help u to draw tree in html . there is many tree menu available but that are not free, try out on google to search it.
Back to top
View user's profile Send private message
Site Admin

Joined: 24 Aug 2006
Posts: 30

PostPosted: Sat Nov 22, 2008 2:55 pm    Post subject: Reply with quote

jQuery TreeView Menu is also option for tree view

check out hot thing of javascript jQuery
Back to top
View user's profile Send private message Send e-mail

Joined: 28 Jun 2008
Posts: 154

PostPosted: Wed Jul 01, 2009 4:46 pm    Post subject: Reply with quote

Hi Friends,

I would like to display database contents as simple treeview structure. The example is given in this website is complicated as i am not able to implement. Can any one help me out how to write simple jsp tree and show the database values? I need to view one field and its values. For example i have to show the clients name as tree view. If i click the client name i have to dispaly the project name. So that i have to render the tree which the value shoud query from the database. Thanks in advance. Have a nice day........

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

Jump to:  
  Quick Post a Reply Topic
  Name (required)  
  Email Address (will not be published) (required)  
  Subject of topic (required)  

  More Links  
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack