因此在此Java servlet中,我在目录中存在一个文件名数组:
String file = "/Library/Tomcat/webapps/HelloServlet/src";
File f = new File(file);
ArrayList<String> names = new ArrayList<String>(Arrays.asList(f.list()));
request.setAttribute("names", names);
request.getRequestDispatcher("main.jsp").forward(request, response);
这部分很好,但是,我正在努力在表中的JSP中打印数组:
<table class="main" id="tableMain">
<thead>
<th scope="col">File Name</th>
<%
if (request.getAttribute("names") != null) {
ArrayList itemsArray = (ArrayList) request.getAttribute("names");
for (int i=0; i < itemsArray.size(); i++) {
out.println("<tr>");
out.println("<td>" + itemsArray.get(i) + "</td>");
out.println("</tr>");
}
}
%>
</table>
任何帮助将不胜感激,在此方面停留了一段时间,非常感谢!!