Easyui filebox File Upload

Source: Internet
Author: User

@RequestMapping (value = "Savefileupload")
@ResponseBody
Public String savefileupload (httpservletrequest request,string menutree,httpservletresponse response) {
String filename= "";
String doctype= "";
Create a general-purpose multi-part parser
Commonsmultipartresolver multipartresolver = new Commonsmultipartresolver (Request.getsession (). GetServletContext () );
Determine if request has a file upload, that is, multipart requests
if (Multipartresolver.ismultipart (request)) {
Convert to multi-part Request
Multiparthttpservletrequest multirequest = (multiparthttpservletrequest) request;
Get all the file names in request
Iterator<string> iter = Multirequest.getfilenames ();

while (Iter.hasnext ()) {
Get upload file
Multipartfile file = Multirequest.getfile (Iter.next ());
if (file! = null) {
Get the file name of the current upload file
String prinames = File.getoriginalfilename ();
String priname=prinames.substring (0,prinames.indexof ("."));
if (! "". Equals (Priname)) {
Rename the uploaded file name

Excelfile = new File (filepath+ "" +prinames);
DocType = Prinames.substring ((Prinames.lastindexof ("."));
Fileuploadservice.savefile (Priname, FilePath, DocType, Menutree);
try {
File.transferto (Excelfile);
} catch (IllegalStateException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
}
}



Return Jsonmapper.getinstance (). ToJson ("Operation succeeded");
}

/*
* File Download
*/
@RequestMapping (value = "Downfile")
@ResponseBody
public void Downfile (String id,httpservletrequest request,httpservletresponse response) {

List<map<string,object>> list=fileuploadservice.downfile (ID);
String filetype=string.valueof (list.get (0). Get ("filetype"));
try{

File File = new file (constant.opload_paht,filename);
Read into the stream
InputStream instream = new FileInputStream (list.get (0). Get ("filecontent") + "" +list.get (0). Get ("filename") + "+" "+ Filetype+ "");//File storage path
Format the output
Response.reset ();
Response.setcontenttype ("bin");
Response.AddHeader ("Content-disposition", "attachment;filename=" + urlencoder.encode (list.get (0). Get ("filename") + FileType, "UTF-8"));
Loop out the data in the stream
Byte[] B = new byte[1000];
int Len;

while (len = Instream.read (b)) > 0)
Response.getoutputstream (). Write (b, 0, Len);
Instream.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}

Easyui filebox File Upload

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.