文件遍历

String uploadPath = ServletActionContext.getServletContext().getRealPath("upload");//上传服务器路径
//遍历文件
File file = new File(uploadPath);
String[] fileName = file.list();
ActionContext ac = ActionContext.getContext();
ac.put("fileName", fileName);
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>文件的遍历</title>
	</head>
	<body>
		<s:form name ="idFrmMain" method="post" action="">
			<table>
				<tr>
					<th align="center">番号</th>
					<th align="center">ファイル名</th>
					<th align="center"></th>
				</tr>
				<s:iterator value="#fileName" status="stat">
				<tr>
					<td align="center">
						<s:property value="#stat.index+1" />
					</td>
					<td align="left">
						<s:property value="#fileName[#stat.index]"/>
					</td>
					<td align="center">
						<a href="#" onclick="javascript:del(this);">削除</a>	
					</td>
				</tr>
				</s:iterator>
			</table>
			<s:hidden name="form.fileFileName" id="fileFileName"></s:hidden>
		</s:form>
	</body>
</html>



function del(el) {
	var tr = el.parentNode.parentNode;//获得削除相对应的行
	var fileFileName = tr.cells[1].innerHTML;//取得该行的第二列的值
	if (confirm(fileFileName + "を削除してもよろしいでしょうか?")) {
		document.getElementById("fileFileName").value = fileFileName;//把文件名的值赋给隐藏表单
		document.idFrmMain.action = "SCR0030303_delete.do";
		document.idFrmMain.target = "_self";
		document.idFrmMain.submit();
	}
}

你可能感兴趣的:(文件遍历)