Java implementation drag-and-drop upload
In the project development due to the actual needs, the need to develop drag-and-drop upload function, ok!
Look first:
JSP upload front-end code:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE html>
OK, after writing the foreground code, in the background, as follows:
<% @page import= "Java.util.UUID"%><% @page import= "Org.apache.commons.fileupload.FileItem"%><% @page Import= "Java.util.Iterator"%><% @page import= "java.util.List"%><% @page import= " Org.apache.commons.fileupload.servlet.ServletFileUpload "%><% @page import=" Org.apache.commons.fileupload.disk.DiskFileItemFactory "%><% @page import=" Org.apache.commons.fileupload.FileItemFactory "%><% @page import=" java.io.File "%><%@ page language=" Java "contenttype=" text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%/*1, File Upload: */request.setcharacterencoding (" Utf-8 "); Response.setcharacterencoding ("Utf-8");//Get File path string Strpath=request.getrealpath ("/") + "/upload"; File file =new file (strpath), if (!file.exists ()) file.mkdirs (); Fileitemfactory factory=new diskfileitemfactory (); Servletfileupload upload=new servletfileupload (Factory);//obtain file information from the Request object list items=upload.parserequest (request); Items!=null) {for (int i=0;i<items.size (); i++) {Iterator iterator=items.iterator(); while (Iterator.hasnext ()) {Fileitem item= (Fileitem) iterator.next (); if (Item.isformfield ()) {continue;} Else{string Filename=item.getname (); Long filesize=item.getsize (); int Pos=filename.indexof ("."); String ext=filename.substring (Pos,filename.length ()); Filename=uuid.randomuuid (). toString () +ext; File Savefile=new file (strpath,filename); Item.write (SaveFile); }}}}%>
OK, at this point, the completion of the drag-and-drop upload function, of course, this is only a rough version, I have optimized the code for the plug-in can be used directly!!
SOURCE Download: Drag and drop upload source code
Java implementation drag-and-drop upload
In the project development due to the actual needs, the need to develop drag-and-drop upload function, ok!
Look first:
Java implementation drag-and-drop upload