1、下载jquery-1.3.1.min.js和jquery.MultiFile.js文件。页面文件如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<script type="text/javascript"
src="jquery-1.3.1.min.js">
</script>
<script type="text/javascript"
src="jquery.MultiFile.js">
</script>
<script type="text/javascript">
$().ready(function(){
$('#logFiles').MultiFile({
accept:'pdf,doc,docx,xls,xlsx,txt,zip,rar',//允许上传的文件类型
STRING: {
remove: '删除',//删除显示的字符串
selected:'该文件已在列表中: $file', //不知道干嘛的
denied:'不能上传该类型文件: $ext!' //类型不匹配的提示
}
});
})
</script>
</head>
<body>
<form name="form1" id="form1" action="proLogAction_saveLog"
method="post" enctype="multipart/form-data">
<p>
<input id="logFiles" name="logFiles" type="file">
</p>
</form>
</body>
</html>
2、struts2 接收 Action
public class ProjectLogAction extends BaseAction {
private List<File> logFiles; //存放文件
private List<String> logFilesFileName;//存放文件名称
public String saveLog() {
if (logFiles != null) {
for (int i = 0; i < logFiles.size(); i++) {
File file = logFiles.get(i);
System.out.println(file.getName());
System.out.println(logFilesFileName.get(i));
}
}
return "lllllll";
}
public void setLogFiles(List<File> logFiles) {
this.logFiles = logFiles;
}
public List<File> getLogFiles() {
return logFiles;
}
public void setLogFilesFileName(List<String> logFilesFileName) {
this.logFilesFileName = logFilesFileName;
}
public List<String> getLogFilesFileName() {
return logFilesFileName;
}
}