Nore
Nore

Reputation: 111

Foreach in JSP to look more directory

I want to get all the file names in a JSP's server directory, and to do that i thought that it would be need some foreach statement, how to do that?

Upvotes: 0

Views: 166

Answers (1)

Kuldeep Jain
Kuldeep Jain

Reputation: 8598

Try this:

File file = new File(request.getRealPath(request.getServletPath()));
File[] fileList = file.getParentFile().listFiles();

You can iterate over this fileList like this:

for (File file : fileList) {
  // Do whatever you want
}

Upvotes: 1

Related Questions