> I'm failing writing a servlet thats display a list of the
> files contained
> by a given diectory.
Here is some sample code which lists some file types in c:/temp:
---------------------Snipped begin------------------------------------
<table border=0 cellspacing=4 cellpadding=0>
<%
File file = new File("c:/temp/");
String[] files = file.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
// I could write that more elegantly:
if (name.endsWith("doc"))
return true;
if (name.endsWith("html"))
return true;
if (name.endsWith("pdf"))
return true;
if (name.endsWith("zip"))
return true;
if (name.endsWith("ppt"))
return true;
return false;
}
});
for (int i = 0; i < files.length; i++)
{
String name = files[i];
String nameShort = files[i].substring(0,
files[i].lastIndexOf("."));
%>
<tr>
<td><a href="<%="docs/" + name %>"><%
if (name.endsWith("doc"))
{
%><img src="images/word.gif" border=0 alt="Microsoft Word"><%
}
else if (name.endsWith("pdf"))
{
%><img src="images/pdf.gif" border=0 alt="PDF"><%
}
else if (name.endsWith("html"))
{
%><img src="images/html.gif" border=0 alt="HTML"><%
}
else if (name.endsWith("zip"))
{
%><img src="images/zip.gif" border=0 alt="ZIP"><%
}
else if (name.endsWith("ppt"))
{
%><img src="images/ppt.gif" border=0 alt="Power Point"><%
}
%></a></td>
<td class="tableCell"><b><a href="<%="docs/" + name %>"><%=nameShort
%></a></b></td>
</tr>
<%
}
%>
</table>
---------------------Snipped end------------------------------------
It's a JSP Page, but that should not make any difference.
Regards
Bernhard
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html