我正在尝试使用下面的代码
开发匹配以下(图像到图像)的应用程序MyJSp.jsp
<div id="container" >
<div>
<span>Question Images</span><br><br>
<img alt="Image1" id="Image1" src="" width="130px" height="90px"><br><br>
<img alt="Image2" id="Image2" src="" width="130px" height="90px"><br><br>
<img alt="Image3" id="Image3" src="" width="130px" height="90px"><br><br>
<img alt="Image4" id="Image4" src="" width="130px" height="90px"><br><br>
<img alt="Image5" id="Image5" src="" width="130px" height="90px"><br><br>
</div>
<div>
<span>Answer Images</span><br><br>
<img alt="Image6" id="Image6" src="" width="130px" height="90px"><br><br>
<img alt="Image7" id="Image7" src="" width="130px" height="90px"><br><br>
<img alt="Image8" id="Image8" src="" width="130px" height="90px"><br><br>
<img alt="Image9" id="Image9" src="" width="130px" height="90px"><br><br>
<img alt="Image10" id="Image10" src="" width="130px" height="90px"><br><br>
</div>
</div>
<span>Upload Image Questions</span><input type="file" id="files1" name="files1[]" value="Upload Questions" multiple><br><br>
Upload Image Answers<input type="file" id="files2" name="files2[]" value="Upload Answers" multiple>
MyJS.js:
$(function(){
document.querySelector('#files1').addEventListener('change', handleFileSelect, false);
document.querySelector('#files2').addEventListener('change', handleFileSelect2, false);
function handleFileSelect(evt) {
// alert();
var files = evt.target.files; // FileList object
// alert("1");
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
reader.onload = (function(theFile, count) {
return function(e) {
if (count > 5)
{
alert("You can upload only 5 images.");
}
else{
$('#Image'+count).prop("src",e.target.result);
make_visible_ADDDB_Count=make_visible_ADDDB_Count+1;
}
};
})(f,i+1);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
// $('.imgclass').draggable();
}
//************ Answer Images Here
function handleFileSelect2(evt) {
var files = evt.target.files; // FileList object
// alert("1");
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
reader.onload = (function(theFile, count) {
return function(e) {
if (count > 5)
{
alert("You can upload only 5 images.");
}
else{
count=count+5;
$('#Image'+count).prop("src",e.target.result);
}
};
})(f,i+1);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
// $('.imgclass').draggable();
}
});
从上面的代码中,用户可以一次上传5张图片,但他们觉得很难一次从单独的文件夹中添加图片。同一时间,如果他们逐个添加,则所有图像仅替换为第一个图像标记。
注意:使用ServletFileUpload.isMultipartContent(request)
那么当使用单个文件上传按钮逐个上传时,如何增加文件数量(如选择5个或2个或3个文件)?
注意:这可能是愚蠢或不可能的问题,但对我来说非常需要。