$ (function () {//$ (' #uploadify '). Uploadifysettings (' folder ', ' JS '); Dynamic modification of the parameter $ ("#uploadify"). Uploadify ({//initialization function width:20, uploader: ' <%=basepath%>resources/lib/uploadify /uploadify.swf ',//flash file location, note path//' swf ': ' <%=basepath%>resources/lib/uploadify/uploadify.swf ', SC Ript: ' <%=basepath%>intentioncontroller.do?method=upload ',//Background processing request (Sevlet) buttonimg: ' <%=BASEPATH%&G T;resources/lib/uploadify/cancel.png ',//upload button background picture auto:true,///Select file automatically upload, default false cancelimg: ' <% =basepath%>resources/lib/uploadify/cancel.png ',//Cancel button picture//' folder ': ' <%=basepath%>resources/lib/uploa Dify/pic ',//You want to save the file to the path, the auto set to true in order to use, or jump to the class to deal with, that's where the final say Queueid: ' Filequeue ',//and the following upload file list ID corresponds to Queuesize Limit:8,//uploading the number of files Scriptdata: {' UserID ': '},//To Background Data filedesc: ',//upload file type says
Ming Fileext: ' jpg,png,gif,jpeg ',//control the extension of the file can be uploaded, when enabling this item must also be declared Filedesc Method: ' Post ',//if data is transferred to the background, it must be the size limit of the Get//sizelimit:10000,//file Upload, in bytes multi:true, Simuploadlimit: 8,//At the same time upload the number of files, set this parameter,//Then you will be set multi:true and Queuesizelimit:8 and can choose more than 8 files,//But if once you will simuploadlimit also set up, then only upload This parameter specifies the number of files, others can not upload buttontext: ' Browse ',//browse button text Oncomplete:function (event, Queueid, Fileobj, Serverda
TA, data) {//When uploading the completed callback function, Ajax way Oh ~ ~//alert ("upload success");
Addimg (Serverdata);
alert (serverdata);
Addimg (Serverdata); /* $ (' #image '). attr ("src", serverdata);//serverdata is the path of Out.print picture in Sevlet $ (' #image '). Show ()
; */}, Onselect:function (E, Queueid, fileobj) {/*alert ("Unique ID:" + queueid + "\ r \ n" + "FileName:" + fileobj.name + "\ r \ n" + "File Size:" + fileobj.size + "\ r \ n" + "Create Time:" + fi
Leobj.creationdate + "\ r \ n" + "Last Modified time:" + fileobj.modificationdate + "\ r \ n" + "File type:" + fileobj.type); */}, Onerror:function (event, Queueid, fileobj) {alert ("File
: "+ fileobj.name + upload failed");
}
}); });
function Addimg (imgurl) {
var path=[];
Path=imgurl.split ("#");
var list=$ ("#imgList");
var img=$ ("
The Java file is like this:
Public String Upload (httpservletrequest request,httpservletresponse response) throws Exception {String BasePath = Reque
St.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + request.getcontextpath () + "/";
String returnpath=basepath+ "Intentionpicture/";
String Savepath =request.getsession (). Getservletcontext (). Getrealpath ("/") + "intentionpicture\\";
File F1 = new file (Savepath);
System.out.println (Savepath);
if (!f1.exists ()) {f1.mkdirs ();
} diskfileitemfactory FAC = new Diskfileitemfactory ();
Servletfileupload upload = new Servletfileupload (FAC);
Upload.setheaderencoding ("Utf-8");
List filelist = null;
try {filelist = upload.parserequest (request);
The catch (Fileuploadexception ex) {} iterator<fileitem> it = Filelist.iterator ();
String name = "";
String extname = "";
while (It.hasnext ()) {Fileitem item = It.next ();
if (!item.isformfield ()) {name = Item.getname (); Long size = Item.getsize ();
String type = Item.getcontenttype ();
SYSTEM.OUT.PRINTLN (Size + "" + type);
if (name = = NULL | | Name.trim (). Equals ("")) {continue;
}//EXTENSION format: if (Name.lastindexof (".") >= 0) {extname = name.substring (Name.lastindexof ("."));
} file file = null;
do {//generate filename: name = Uuid.randomuuid (). toString ();
File = new file (Savepath + name + extname);
System.out.println (Savepath + name + extname);
while (File.exists ());
File SaveFile = new file (Savepath + name + extname);
try {item.write (savefile);
catch (Exception e) {e.printstacktrace ();
}} return Returnpath+name + extname+ "#" +SAVEPATH+NAME+EXTNAME; }
The JSP file is like this:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">