Absrtact: JS Submission Form (The purpose is to do non-null check), upload multiple files, avoid using <button> prevent form automatic submission
HTML code:
<form id= "Add_open" action= "Rest/admin/library/add_open" method= "post" enctype= "Multipart/form-data" >
<div class= "White_title" >
<span class= "Dangqian" > Open Class >></span> new Open Class
</div>
<div class= "Curric_form" >
<div class= "Curric_name" >
Course Name
</div>
<div class= "Curric_ipt" >
<input type= "text" class= "Open_name" name= "Coursetitle"/>
</div>
</div>
<div>
<input type= "File" class= "file_photo_img" id= "file_img" name= "file_img" >
<input class= "Murric_file" type= "file" id= "Coursevideopath" name= "Coursevideopath" multiple>
<input class= "Murric_file" type= "file" id= "Coursevideopath" name= "Coursevideopath" multiple>
</div>
</form>
JS Code:
$ (". Open_save"). Bind ("click", Function ()
{
Non-null checksum
$ ("#add_open"). Submit ();
})
Controller code:
@RequestMapping (value = "/add_open", method = Requestmethod.post, produces = "Application/json")
@ResponseBody
public void Addopen (@RequestParam ("Coursevideopath") multipartfile[] coursevideopath,httpservletrequest request, HttpServletResponse response) throws IOException
{
...
for (int i=0; i<chapternames.length; i++) {//Loop get File Upload Object
Librarycoursehapters l=new librarycoursehapters ();
L.setchaptername (Chapternames[i]);
L.setclasshours (Chapterhourss[i]);
Upload Video
String Savevideopath = Request.getservletcontext (). Getrealpath ("/uploadvideo") + "/";
File File=new file (Savevideopath);
if (!file.exists ()) {
File.mkdirs ();
}
String Videoname=coursevideopath[i].getoriginalfilename ();
String suffix=videoname.substring (Videoname.lastindexof ("."));
String newvideoname = new SimpleDateFormat ("Yyyymmddhhmmssss"). Format (new Date ()) + uuid.randomuuid () + suffix;
if (!coursevideopath[i].isempty ()) {
try {
FileOutputStream fos = new FileOutputStream (savevideopath+newvideoname);
Get the original file name
InputStream In=coursevideopath[i].getinputstream ();
int b = 0;
while ((b = in.read ())!=-1) {
Fos.write (b);
}
Fos.close ();
In.close ();
catch (Exception e) {
msg + = "information is wrong";
E.printstacktrace ();
}
}
L.setcoursevideopath ("/uploadvideo/" +newvideoname);
...
}
Application: Can realize the table data submission, realizes the data verification in the JS, realizes the complex business logic processing