Springmvc use JS submit form upload multiple files, and how to prevent form automatic submission __js

Source: Internet
Author: User

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

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.