这就是我解决问题的方法:
<tr>
<td> Step 1 :
<td>
<input type="hidden" name="isFileUpload" id="id-is-file-upload-0" value="0">
<textarea id="id-solution-0" name="processSolutionSteps" rows="2" cols="50" maxlength="200" class="class-text-area class-text-area-not-blank"></textarea>
<!-- <input type="text" id="id-solution-0" name="processSolution" maxlength="30" size="35"> -->
<p id="id-process-solution-counter-0"></p>
</td>
<td>
<input type="file" id="id-file-0" name="uploads">
</td>
</tr>
<tr>
<td> Step 2 :
<td>
<input type="hidden" name="isFileUpload" id="id-is-file-upload-1" value="0">
<textarea id="id-solution-1" name="processSolutionSteps" rows="2" cols="50" maxlength="200" class="class-text-area class-text-area-not-blank"></textarea>
<!-- <input type="text" id="id-solution-1" name="processSolution" size="35"> -->
<p id="id-process-solution-counter-1"></p>
</td>
<td>
<input type="file" id="id-file-1" name="uploads">
</td>
</tr>
<tr>
<td> Step 3 :
<td>
<input type="hidden" name="isFileUpload" id="id-is-file-upload-2" value="0">
<textarea id="id-solution-2" name="processSolutionSteps" rows="2" cols="50" maxlength="200" class="class-text-area class-text-area-not-blank"></textarea>
<!-- <input type="text" id="id-solution-2" name="processSolution" size="35"> -->
<p id="id-process-solution-counter-2"></p>
</td>
<td>
<input type="file" id="id-file-2" name="uploads">
</td>
</tr>
我只是发布了我的<tr>
标签的一些示例代码
我维护了一个初始值为0的隐藏字段 ,没有多少。我的,上传文件后,在其更改事件中,我将值更改为1isFileUpload
<input type="file">
isFileUpload
$('#id-solution-table').on('change', 'input[type=file]', function () {
$('#id-is-file-upload-'+$(this).prop("id").split("-")[2]).val(1);
});
在我的行动课上,我有这个代码
根据isFileUpload
ie 的值,我用1检查了它,
意味着我已经在这个索引位置上传了文件并映射了上传的文件数组,它是uploads
private File [] uploads;
private String [] uploadsFileName;
private String [] uploadsContentType;
private short isFileUpload [];
try {
int fileIndex = 0;
for (int i = 0; i < this.isFileUpload.length; i++) {
if( this.isFileUpload[i] == 1 ) {
System.out.println(" index "+i+ " isFileUpload "+this.isFileUpload[i]);
System.out.println("Index "+i+ " "+this.uploadsFileName[ fileIndex ]);
String filePath = path;
new File(filePath).mkdirs();
FileUtils.copyFile(this.uploads[ fileIndex ], new File(filePath+"/"+i+"."+FilenameUtils.getExtension(this.uploadsFileName[ fileIndex ])));
++fileIndex;
}
}
} catch(Exception exception) {
addActionError("Some files not uploaded.");
exception.printStackTrace();
}