jquery uploadify的JS用法以及JAVA类的用法

[javascript] view plain copy
  1. $(function(){
  2. //$('#uploadify').uploadifySettings('folder','JS');//动态修改参数
  3. $("#uploadify").uploadify({//初始化函数
  4. width:20,
  5. uploader:'<%=basePath%>resources/lib/uploadify/uploadify.swf',
  6. //flash文件位置,注意路径
  7. //'swf':'<%=basePath%>resources/lib/uploadify/uploadify.swf',
  8. script:'<%=basePath%>IntentionController.do?method=upload',
  9. //后台处理的请求(sevlet)
  10. buttonImg:'<%=basePath%>resources/lib/uploadify/cancel.png',
  11. //上传按钮的背景图片
  12. auto:true,
  13. //选定文件后是否自动上传,默认false
  14. cancelImg:'<%=basePath%>resources/lib/uploadify/cancel.png',
  15. //取消按钮图片
  16. //'folder':'<%=basePath%>resources/lib/uploadify/pic',//您想将文件保存到的路径,将auto设置为true里才有用,不然跳到类里去处理,那就那里说了算
  17. queueID:'fileQueue',
  18. //与下面的上传文件列表id对应
  19. queueSizeLimit:8,
  20. //上传文件的数量
  21. scriptData:{
  22. 'userID':''
  23. },
  24. //向后台传的数据
  25. fileDesc:'',
  26. //上传文件类型说明
  27. fileExt:'jpg,png,gif,jpeg',
  28. //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
  29. method:'post',
  30. //如果向后台传输数据,必须是get
  31. //sizeLimit:10000,//文件上传的大小限制,单位是字节
  32. multi:true,
  33. simUploadLimit:8,
  34. //同时上传文件的数量,设置了这个参数后,
  35. //那么你会因设置multi:true和queueSizeLimit:8而可以多选8个文件,
  36. //但如果一旦你将simUploadLimit也设置了,那么只会上传这个参数指定的文件个数,其它就上传不了
  37. buttonText:'BROWSE',
  38. //浏览按钮上的文字
  39. onComplete:function(event,queueID,fileObj,serverData,data){//当上传完成后的回调函数,ajax方式哦~~
  40. //alert("上传成功");
  41. addImg(serverData);
  42. //alert(serverData);
  43. //addImg(serverData);
  44. /*$('#image').attr("src",serverData);//serverData是sevlet中out.print图片的路径
  45. $('#image').show();*/
  46. },
  47. onSelect:function(e,queueId,fileObj){
  48. /*alert("唯一标识:"+queueId+"\r\n"+
  49. "文件名:"+fileObj.name+"\r\n"+
  50. "文件大小:"+fileObj.size+"\r\n"+
  51. "创建时间:"+fileObj.creationDate+"\r\n"+
  52. "最后修改时间:"+fileObj.modificationDate+"\r\n"+
  53. "文件类型:"+fileObj.type
  54. );*/
  55. },
  56. onError:function(event,queueID,fileObj){ alert("文件:"+fileObj.name+"上传失败");
  57. }
  58. });
  59. });


[javascript] view plain copy
  1. functionaddImg(imgUrl){
  2. varpath=[];
  3. path=imgUrl.split("#");
  4. varlist=$("#imgList");
  5. varimg=$("<img>");
  6. img.attr("src",path[0]);
  7. img.attr("id",path[1]);
  8. img.attr("height","150px");
  9. img.attr("width","150px");
  10. img.click(function(){
  11. alert("设为首页募捐显示照片吗?");
  12. });
  13. img.css("cursor","pointer");
  14. list.append(img);
  15. //proDownImage(path[0],img);
  16. }


JAVA文件是这样的:

[java] view plain copy
  1. publicStringupload(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{
  2. StringbasePath=request.getScheme()+"://"
  3. +request.getServerName()+":"+request.getServerPort()
  4. +request.getContextPath()+"/";
  5. StringreturnPath=basePath+"intentionPicture/";
  6. StringsavePath=request.getSession().getServletContext().getRealPath("/")+"intentionPicture\\";
  7. Filef1=newFile(savePath);
  8. //System.out.println(savePath);
  9. if(!f1.exists()){
  10. f1.mkdirs();
  11. }
  12. DiskFileItemFactoryfac=newDiskFileItemFactory();
  13. ServletFileUploadupload=newServletFileUpload(fac);
  14. upload.setHeaderEncoding("utf-8");
  15. ListfileList=null;
  16. try{
  17. fileList=upload.parseRequest(request);
  18. }catch(FileUploadExceptionex){
  19. }
  20. Iterator<FileItem>it=fileList.iterator();
  21. Stringname="";
  22. StringextName="";
  23. while(it.hasNext()){
  24. FileItemitem=it.next();
  25. if(!item.isFormField()){
  26. name=item.getName();
  27. longsize=item.getSize();
  28. Stringtype=item.getContentType();
  29. //System.out.println(size+""+type);
  30. if(name==null||name.trim().equals("")){
  31. continue;
  32. }
  33. //扩展名格式:
  34. if(name.lastIndexOf(".")>=0){
  35. extName=name.substring(name.lastIndexOf("."));
  36. }
  37. Filefile=null;
  38. do{
  39. //生成文件名:
  40. name=UUID.randomUUID().toString();
  41. file=newFile(savePath+name+extName);
  42. //System.out.println(savePath+name+extName);
  43. }while(file.exists());
  44. FilesaveFile=newFile(savePath+name+extName);
  45. try{
  46. item.write(saveFile);
  47. }catch(Exceptione){
  48. e.printStackTrace();
  49. }
  50. }
  51. }
  52. returnreturnPath+name+extName+"#"+savePath+name+extName;
  53. }


JSP文件是这样的:

[html] view plain copy
  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
  5. <title>MyJSP'aaa.jsp'startingpage</title>
  6. <linkhref="../../resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css"
  7. rel="stylesheet"type="text/css"/>
  8. <link
  9. href="../../resources/ldcss/ldform.css"
  10. rel="stylesheet"type="text/css"/>
  11. <linkhref="../../resources/ldcss/global.css"rel="stylesheet"type="text/css"/>
  12. <linkhref="<%=basePath%>resources/lib/uploadify/uploadify.css"rel="stylesheet"type="text/css"/>
  13. <scriptsrc="<%=basePath%>resources/ldjs/global.js"type="text/javascript"></script>
  14. <scriptsrc="<%=basePath%>resources/lib/jquery/jquery-1.7.1.min.js"type="text/javascript"></script>
  15. <scripttype="text/javascript"src="<%=basePath%>resources/lib/uploadify/swfobject.js"></script>
  16. <scripttype="text/javascript"src="<%=basePath%>resources/lib/uploadify/jquery.uploadify.v2.1.0.min.js"></script>
  17. </head>
  18. <body>
  19. <divid="fileQueue"></div>
  20. <inputtype="file"name="uploadify"id="uploadify"/>
  21. <p>
  22. <ahref="javascript:jQuery('#uploadify').uploadifyUpload()">开始上传</a>
  23. <ahref="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a>
  24. </p>
  25. <divid="imgList"></div>
  26. </body>
  27. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值