Java Web project implements multiple attachment uploads

Source: Internet
Author: User
Tags dateformat filetime

JSP Code:

<div class= "Col-md-8 col-sm-8" >
<a href= "# # #" onclick= "addcomponent ();" >
Add attachment </a><font color= "Red" >&nbsp;&nbsp;&nbsp; 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.