Monday, 21st June 2010
The new frontier for learning Java

Get a list of directories for JSP

From WikiJava

Jump to: navigation, search


this example shows how to render with a JSP the directory listing on the hard disk on the server.

Contents

the article

the example uses dir.list() to print on the user's browser page the list of a directory on the server.

directories jsp

<h1>Directories</h1>
<ul>
<%
String root="c:/Repository/WebApplication/mydocs/javadoc/";
java.io.File file;
java.io.File dir = new java.io.File(root);
 
String[] list = dir.list();
 
for (int i = 0; i < list.length; i++) {
  file = new java.io.File(root + list[i]);
  if (file.isDirectory()) {
  %>
  <li><a h ref="javadoc/<%=list[i]%>" target="_top"><%=list[i]%></a><br>
  <%
     }
  }
%>
</ul>


See Also

Real's Java How To

Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Title (required):

Website:

Comment: