tags:

views:

1096

answers:

1

When writing a JSP file, how can I get the current directory of this file at runtime
(to be able to iterate the directory and list its contents)?

Would some file I/O operations be restricted because of some security issues?

I would prefer a solution without accessing some implementation-specific server variables / properties.

EDIT:
I wouldn't ask if it were as simple as new File("."), because this would just give the directory of server's executables.

+2  A: 

you should know the path of the jsp within your web application so you can pass that to getRealPath()

File jsp = request.getRealPath(pathToJspInWebapp);  //eg. /WEB-INF/jsp/my.jsp
File directory = jsp.getParentFile();
File[] list = directory.listFiles();
objects