文件遍历

9 篇文章 0 订阅
8 篇文章 0 订阅
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="#" οnclick="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();
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值