Get file names in a directory with JSP

0

I have a Web system in which I have a folder with files and what I'm trying to do is bring the names of the files into that folder.

Command to call a JSP from JS :

getUrlJsonObject({
  href:pathcamp+'getNamesDocs.jsp',
  method:"GET",  
},
function(data){}

this is the JSP

<%
    final File folder = new File("/docs");
    for (final File fileEntry : folder.listFiles()) {
        if (fileEntry.isDirectory()) {
            listFilesForFolder(fileEntry);
        } else {
            System.out.println(fileEntry.getName());
        }
    }
    listFilesForFolder(folder);
%>

But I get the following error:

An error occurred at line: 2 in the jsp file: getNamesDocs.jsp
File cannot be resolved to a type
1: <%
2:  final File folder = new File("/docs");
3:  for (final File fileEntry : folder.listFiles()) {
4:      if (fileEntry.isDirectory()) {
5:  

    listFilesForFolder(fileEntry);

Thanks in advance.

    
asked by Alejandro Gonzalez 26.04.2018 в 01:03
source

1 answer

1

If that is the complete content of your JSP file, you would need to import the class that contains the type File . To import it you must include this line at the beginning of your .jsp file:

import java.io.File;
    
answered by 26.04.2018 / 02:51
source