#getFileDir.py
from java.lang import *
from javax.servlet import *
from javax.servlet import http
import string , jarray
toclient = None
def recurse_directory (context,list_dir):
global toclient
for i in range(len(list_dir)):
if list(context.getResourcePaths(list_dir[i]).toArray()) == []:
#If the return value is empty list , it is a file
toclient.println("
" + list_dir[i])
#Print the real path of the file
toclient.println("
" + "Path = " + context.getRealPath(list_dir[i]) + "
" )
else:
#Directory found, recurse through the current directory
recurse_directory(context,list(context.getResourcePaths(list_dir[i]).toArray()))
class getFileDir (http.HttpServlet):
def doGet(self, req, res):
global toclient
#Set Response ContentType
res.setContentType("text/html")
#Get a new Writer to print the Response in the browser
toclient = res.getWriter()
toclient.println("The files and directories in the current context are ....
")
#Get the current servlet context
context = http.HttpServlet.getServletContext(self)
#Get the directory and the file listing for the above context
#at the topmost level
resource_path = list(context.getResourcePaths("/").toArray())
#Recurse through the current context to traverse all directories
recurse_directory(context , resource_path)
toclient = None