File tree servlet 1.1

It is a Java servlet lets you obtain file tree info in JSON format. You can use this servlet in your client site (JavaScript) code for getting file info from your server.

How to use it:

a) copy filetreePackage.jar into your WEB-INF/lib directory.

b) define FileTreeServlet in your web.xml file.


c) define a mapping:


you can pass a name for the directory (or file) you are interested in as a parameter dir. And parameter callback describes a name for your JavaScript function (JSONP). E.g. the following code lists data from the directory /WEB-INF/data:


function f(dir)
var cbscript = document.createElement("script");
cbscript.src = "http://myhost/servlet/filetree?dir="+dir+"&callback=c";
cbscript.type = 'text/javascript';

function c(list)
var s="";
for (var i=0; i {
var o = list[i];

if (o.isDir=="true")


<input type="button" onClick="f('WEB-INF/data')" value="Get dir"/>

<div id="d">


our JavaScript callback gets back an array with info about files. You can obtain the following information about each object:

isDir possible values are true or false - is it directory or file
name describes a name
size describes a size for file
lastModified describes a last modified time

Also you can describe an initital parameter for this servlet: root. This parameter describes some directory on your server and restricts access to the server-side file system to this directory and its sub-directories only. Parameter dir (if any) describes in this case a subdirectory. E.g.:


and /servlet/filetree?dir=pics will describe actually a directory /WEB-INF/data/pics

    For downloading:   filetreePackage.jar

 © Coldbeans Software     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: