JAVA JSP examples

Do not run this file locally
Run it from your (local) web server where is installed your http and JSP server like Apache Tomcat and the J2SE runtime environment (JRE).

The JSP service program must have write access to all files database.* and also must have write access to the directory /Examples/Jsp/ and its subdirectories
To permit write access on Windows XP right click to folder Jsp in My Computer, select Properties -> Security -> Users and set Full control to Allow. If you don't have Security item in Properties, run My Computer, in menu select Tools - > Folder options -> View and uncheck Use simple file sharing option.

You have to copy files hsqldb.jar and TreeGrid.jar to your JRE shared lib directory and restart your http server
These files are located in TreeGrid distribution in /Server/JSP/ directory.
The shared lib directory is usually jre_install_path/lib/ext and also for example in Tomcat is usually tomcat_install_path/shared/lib.
hsqldb.jar file is JDBC driver for HSQLDB database that is used in nearly all examples.
TreeGrid.jar is support code for using TreeGrid server side library, this library is used in example Ajax grids with using server DLL/SO.


TreeGrid JSP Framework

When writing JSP script you can use TreeGrid JSP framework functions to help generating and parsing XML files and reading it from and updating changes to database.
The framework is located in single file TreeGridFramework.jsp and can be included into your JSP pages by standard include mechanism
<%@include file="path/TreeGridFramework.jsp"%>.
See TreeGrid JSP framework documentation.
Nearly all examples use this framework, so look at them to learn how to use the framework.


Example index

Basic AJAX
Basic usage of asynchronous background (new style) communication with server and SQL database communication
Basic AJAX The simplest demonstration of using JSP and AJAX link
Using TreeGrid JSP framework How to generate data from and update data to SQL database using prepared TreeGridFramework.jsp link
Tree in database How to generate tree from and store tree to SQL database table link
TreeGrid API for communication and reloading Using TreeGrid Extended API link
 
Basic <form> Submit
Basic usage of synchronous (old style) communication with server and SQL database communication
DataTable database access The simplest demonstration of using JSP and <form> submit link
Using TreeGrid JSP framework How to generate data from and update data to SQL database using prepared TreeGridFramework.jsp link
Tree in database How to generate tree from and store tree to SQL database table link
 
Applications
Few more complex applications with TreeGrid upon SQL database and AJAX communication
Grid from database table Demonstrates advanced generating from and updating to database link
Complete application - Schools Complete application to demonstrate generating from and updating to different database tables with various structure link
File and directory browser Demonstration of manipulating files and directories with TreeGrid link
 
Server paging
Examples of writing server side support scripts for server side paging upon SQL database
Sorting, uploading changes and export Demonstrates sorting feature, saves changes back to database, supports also export to Excel, all upon SQL database link
Grouping Demonstrates grouping with server paging and client child paging - all children from groups are sent to server at once link
Grouping with server child paging Demonstrates grouping with server paging and also server child paging link
 
Server paging with TreeGrid server library
Examples of writing server side support scripts for server side paging with helper library shipped with TreeGrid
DataTable database access Demonstrates using TreeGrid server library upon SQL database link
Complex application upon XML file Shows using TreeGrid server library upon XML file on disk with all supported features, especially grouping link
Sharing and synchronization upon XML file Shows sharing data among more clients and automatic updating client's data after data on server are modified by another client link


Basic AJAX

Basic usage of asynchronous background (new style) communication with server.
Basic demonstration of generating data from and uploading data to SQL database.
All examples are located at "Examples/JSP/BasicAjax/.." directory.
Data are downloaded from or uploaded to server by JavaScript XmlHttpRequest object on background, without reloading/submitting the page content.
You can check from configuration menu option Auto update changes to server for immediate updates after edit/modify.
When debugging, you can set <treegrid ... Debug='3' ... > to see communication with server. It opens two new browser's windows. You can see XML data or JSP error server returned.
Remember, in Ajax communication, the JSP page must return only xml data, not any standard html tags like <html> or <!doctype>.
See documentation
AJAX versus submit and also tutorial Identifying rows when uploading.

Basic AJAX
Main file Basic.html, support code Basic.jsp
Layout file in DBDef.xml, data in database table "TableData".
The simplest demonstration of using JSP and AJAX. It generates data from database table 1:1 including id. Also updates changes to database according to id.

Using TreeGrid JSP framework
Main file Framework.html, support code Framework.jsp, framework code /Framework/TreeGridFramework.jsp
Layout file in DBDef.xml, data in database table "TableData".
The same example as previous one, but with using functions from TreeGrid JSP Framework. It also shows using custom parameters in <treegrid> tag.

Tree in database
Main file TreeFramework.html, support code TreeFramework.jsp, framework code /Framework/TreeGridFramework.jsp
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid JSP Framework.

TreeGrid API for communication and reloading
Main file API.html, support codes Framework.jsp and TreeFramework.jsp, framework code /Framework/TreeGridFramework.jsp
Layout files in DBDef.xml and TreeDef.xml, data in database tables "TableData" and "TreeData".
It shows two tables from previous examples and demonstrates Extended API functions for reloading, changing data source when reloading, catching data event and so on.


Basic <form> Submit

Basic usage of synchronous (old style) communication with server.
Basic demonstration of generating data from and uploading data to SQL database.
All examples are located at "Examples/JSP/BasicSubmit/.." directory.
Data are included in page in hidden <input>. Changes are sent to server in this hidden <input> of submitted <form> on page.
See documentation
AJAX versus submit and also tutorial Identifying rows when uploading.

Basic Submit
Main file Basic.jsp
Layout file in DBDef.xml, data in database table "TableData".
The simplest demonstration of using JSP and standard page submit. It generates data from database table 1:1 including id. Also updates changes to database according to id.

Using TreeGrid JSP framework
Main file Framework.html, framework code /Framework/TreeGridFramework.jsp
Layout file in DBDef.xml, data in database table "TableData".
The same example as previous two, but with using functions from TreeGrid JSP Framework. Also shows using custom parameters.

Tree in database
Main file TreeFramework.jsp, framework code /Framework/TreeGridFramework.jsp
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid JSP Framework.


Applications

Few more complex applications with TreeGrid upon SQL database and AJAX communication.

Grid from database table
Main file Grid.html, support codes GridLayout.jsp as layout, GridData.jsp as data, GridUpload.jsp as upload
Data are in database table "TableData".
Demonstrates advanced generating from and updating to database.
Generates treetable from standard database table. Also flips the table and shows data in changed layout.
For every action there is used another support code (Layout, Data, Upload). The layout is also generated.
Rows are identified by one unique editable column, with using full ids (including parents ids).
For demonstration it shows id column, to see what ids are generated by TreeGrid.

Complete application - Schools
Main file Schools.html
Support codes Schools.jsp (main file generates data and also saves changes to database or adds new user),
SchoolsRatings.jsp (loads reviews for given record, used for server child paging),
SchoolsReview.jsp (saves one review to database, called as custom AJAX call).
Layout file in SchoolsDef.xml, data in database tables "Schools_Schools", "Schools_Ratings" and "Schools_Users".
Uses also file SchoolsStars.gif ()
Complete application to demonstrate generating from and updating to different database tables with various structure. Demonstrates also server child paging feature (loading children on demand). And also custom AJAX call.
The application show list of schools that can be sorted and filtered. The records can be added/deleted or modified by logged user or admin. The records can be rated and reviewed by visitors.


File and directory browser
Main file Browser.html, layout file BrowserDef.xml, script returning directory and file tree BrowserData.jsp as data xml.
Suppors JavaScript is in Browser.js, the sample directory tree is located in TestFiles/ subdirectory.
The files can be shown in directories or as direct list, also various sorting and filtering is possible.
The files can be added, moved, deleted, copied and viewed by clicking to left panel of by right click popup menu.
The sample directories and files are located in /TestFiles directory and are independent on the examples distribution so they can be modifed or deleted without problems. The changes are done after click to Save button.


Server paging

Examples of writing server side support scripts for server side paging upon SQL database.
Demonstration of implementation of various TreeGrid features, like sorting, grouping and export.
All examples use AJAX communication (server side paging cannot be done by synchronous communication).
All examples are located at "Examples/JSP/Paging/.." directory.

Sorting, uploading changes and export to Excel
Main file SortingExport.html
Layout is in static file SortingExport_Layout.xml
Script for generating data (page list) SortingExport_Data.jsp
Script for uploading changes back to database SortingExport_Upload.jsp
Script for generating individual page SortingExport_Page.jsp
Script for exporting data to Excel SortingExport_Export.jsp
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates sorting feature, saves changes back to database, supports also export to Excel.
The pages are downloaded on demand from server (when the page is visible by scrollbars).
It is simple example with ineffective database access - it loads all table for every page and throws the rest away.
It also simply reloads all body when rows are added or deleted instead of handling changes in pages.

Grouping
Main file Grouping.html
Layout is in static file Grouping_Layout.xml
Script for generating data (page list) Grouping_Data.jsp
Script for generating individual page Grouping_Page.jsp
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates grouping feature.
Demonstrates server paging but client child paging - all children from groups are sent to server at once.
This is only simple example with not ideal database access (for every page gets all data)
The pages are downloaded on demand from server (when the page is visible by scrollbars).

Grouping with server child paging
Main file GroupingChild.html
Layout is in static file (the same as in previous example) Grouping_Layout.xml
Script for generating data (page list) (the same as in previous example) Grouping_Data.jsp
Script for generating individual page and for individual groups GroupingChild_Page.jsp
Data are in database table "TableData".
Demonstrates server side paging upon SQL database. Demonstrates grouping feature.
Demonstrates server paging with server child paging - group downloads its children only when it is expanded.
This is only simple example with not ideal database access (for every page gets all data)
The pages are downloaded on demand from server (when the page is visible by scrollbars).


Server paging with TreeGrid server library

Examples of writing server side support scripts for server side paging with helper library shipped with TreeGrid.
Demonstration of implementation of various TreeGrid features, like sorting, filtering, grouping and export.
All examples use
TreeGrid server library The library is named TreeGrid.dll for Windows and TreeGrid.so for Linux and is located at /Server/TreeGrid.dll(.so)
To run these examples you must copy TreeGrid.jar to your shared lib directory.
Some examples stores data in SQL database, some on disk in XML files.
All examples use AJAX communication (server side paging cannot be done by synchronous communication).
All examples are located at "Examples/JSP/PagingDLL/.." directory.

You can compare these example with the examples in previous section (Server paging) how TreeGrid server library simplifies server side paging implementation.

Using SQL database
Main file DB.html, support code DB.jsp
Layout file in DBDef.xml, data in database table "TableData".
Demonstration of using TreeGrid server library for server side paging upon SQL database.
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.

Complex application upon XML file
Main file File.html, support code File.jsp
Layout file in FileDef.xml, data in file FileData.xml.
Demonstration of using TreeGrid server library for server side paging upon XML file on disk.
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.
It demonstrates especially complex grouping feature and cell editing in various groups.
The complete description is in the example itself.

Sharing and synchronization upon XML file
Main file FileSharing.html, support code FileSharing.jsp
Layout file in FileDef.xml, data in file FileData.xml.
Demonstration of using TreeGrid server library for server side paging upon XML file on disk.
This example shows all TreeGrid features sorting, filtering, grouping, calculations, uploading changes and export to Excel.
Demonstrates sharing data among more clients and automatic updating client's data after data on server are modified by another client.
The complete description is in the example itself.