JSP traverse the file under the folder code _jsp programming
Source: Internet
Author: User
Displayfile.java
//*********************************
File parentdirectory = null;//current directory
ArrayList [] File = null;//holds all files in the current directory
ArrayList [] directory = null;//holds all directories in the current directory
string [] temp = null;//Temporary array holds the absolute path of all files and directories in the current directory plus the full name string
File tempfile = null;
if (Request.getparameter ("directory") ==null)
{
Parentdirectory = new File ("c://temp");//Use the servlet for the first time using the default directory for Access objects
}
Else
{
Use the page submitted directory as the default directory for the second or subsequent visit
Parentdirectory = new File (request.getparameter ("directory"));
}
temp = Parentdirectory.list ();//extract absolute path of all files and directories in the current directory plus full name string
for (int i = 0; I<list.length (); i++) {
To make a judgment is to put the directory into the directory collection of files in the file collection
Tempfile = new File (temp)
if (Tempfile.isdirectory ())
Directory.add (Tempfile);
Else
File.add (Tempfile);
}
//*********************************
Then use the two collections in the JSP page to display the directory and file directories you can use the Super connection to invoke the above servlet again
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.