Java implementation drag-and-drop upload

Source: Internet
Author: User


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

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.