JSP Code:
<div class= "Col-md-8 col-sm-8" >
<a href= "# # #" onclick= "addcomponent ();" >
Add attachment </a><font color= "Red" > each attachment size cannot exceed 50m</font>
</div>
JS Code:
function AddComponent ()
{
var flag = document.getElementById ("Numsize"). Value;
if (flag>9) {
Alert ("You cannot add more than 10 attachments!");
return false;
}else{
FCC = document.createelement ("P");
document.getElementById ("Files"). appendchild (FCC);
Counter to count the number of file
var numsize = document.getElementById ("Numsize"). Value;
var numsize = number (numsize) +number (1);
document.getElementById ("Numsize"). Value=numsize;
//
var fc = document.getElementById ("Count"). Value;
var count = number (FC) +number (1);
document.getElementById ("Count"). Value=count;
var uploadhtml = document.createelement ("input");
Uploadhtml.setattribute ("type", "file");
Uploadhtml.setattribute ("name", "Filegg");
Uploadhtml.setattribute ("id", count);
Uploadhtml.setattribute ("Style", "max-width:300px;word-break:break-all;display:inline-block;");
document.getElementById ("Files"). AppendChild (uploadhtml);
var a = document.createelement ("a");
var node = document.createtextnode ("delete");
A.appendchild (node);
A.setattribute ("href", "# # #");
A.setattribute ("id", "btn (" +count+ ")");
A.setattribute ("Style", "display:inline-block;");
A.setattribute ("onclick", "FC (" +count+ ")");
var img = document.createelement ("img");
Img.setattribute ("src", "${ctx}/image/activity/slider/delete.png");
Img.setattribute ("id", "img (" +count+ ")");
Img.setattribute ("Style", "display:inline-block;");
Img.setattribute ("height", "15px");
Img.setattribute ("width", "15px");
Img.setattribute ("Class", "lessimg");
A.appendchild (IMG);
document.getElementById ("Files"). AppendChild (a);
}
}
Background code:
if (filegg!=null) {
Uploading attachments
for (int i=0; i < filegg.size (); i++) {
Activityfile entityfiletemp = new Activityfile ();
Storage path
String Path = "/upload/" +entity.getrandom () + "/" +fileggfilename.get (i);
String Randomuuid = Uuid.randomuuid (). toString ();
String Extendf=fileggfilename.get (i). substring (Fileggfilename.get (i). LastIndexOf ("."));
String Path = "/upload/" +random+ "/" +RANDOMUUID+EXTENDF;
String anothername = randomuuid+extendf;
The path of the file before the change
String totalfilepath=dstpath1 + file.separator +fileggfilename.get (i);
The path of the file after the change
String newtotalfilepath=dstpath1 + file.separator + randomuuid+extendf;
File path (that is, file) before changing
File Totalactivityfile=new file (totalfilepath);//Gets the destination address of the stored file
File path after the change (i.e. file)
File Newtotalactivityfile=new file (newtotalfilepath);//Gets the destination address of the stored file
Change file
Totalactivityfile.renameto (Newtotalactivityfile);
String Activityfilename=this.fileggfilename.get (i);
/*userservice.upload (Filegg.get (i), totalactivityfile); Uploading attachments
* */
Userservice.upload (Filegg.get (i), newtotalactivityfile);
Entityfiletemp.setrounte (path);
ENTITYFILETEMP.SETRANDOMF (random);
Entityfiletemp.setanotherfilename (Anothername);
Entityfiletemp.setfilename (Activityfilename);
SimpleDateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd hh:mm");//You can easily modify the date format
String fileTime = Dateformat.format (New Date ());
Entityfiletemp.setfiletime (FileTime);
Entityfiletemp.setfileflag ("0");
Entityfiletemp.setdeptcode ("0");
Activityfile.add (entityfiletemp);
}
}
Java Web project implements multiple attachment uploads