我描述一下,就是使用jquery的插件结合struts2来做一个文件上传。且带进度条。
页面代码:   <!-- jquery 文件上传插件 -->
    <link href="css/default/uploadify.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/default/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="js/default/swfobject.js"></script>
        <script type="text/javascript" src="js/default/jquery.uploadify.v2.1.0.js"></script>
<!-- end -->
        <script type="text/javascript"> 
      
       //后台需要的一些列参数
        function fileUpload(){
          $('#file1').uploadifySettings('scriptData', 
              { 
              'bidDocumentType':'1', 
              'bidFile.tenderid': '${tender.id}',
              'bidFile.projectid':'${tender.projectid}',
              'bid.companyid':'${bid.companyid}',
              'bid.addr':'${bid.addr}',
              'bid.taxno':'${bid.taxno}',
              'bid.businessentity':'${bid.businessentity}',
              'bid.contactname':'${bid.contactname}',
              'bid.fax':'${bid.fax}',
              'bid.tel':'${bid.tel}',
              'bid.email':'${bid.email}',
              'tender.id':'${tender.id}',
              'tender.projectid':'${tender.projectid}'
               });
             
          $('#file1').uploadifyUpload(); //jQuery('#file1').uploadifyUpload()
        }
        
        
    $(document).ready(function() {
             $("#file1").uploadify({
               'uploader'       : 'swf/uploadify.swf',
               'script'         : 'bidUploadOrDown_uploadBidDocument.action',
               'cancelImg'      : 'images/jqueryUpload/cancel.png',
              // 'folder'         : 'uploads',
                'fileDataName'  :'file',
                'sizeLimit'     : 1024*1024*100,
               'auto'           : false,
               'multi'          : false,
               'simUploadLimit' : 2,
                'fileDesc':'请选择rar,doc,pdf,txt文件',
                'fileExt':'*.doc;*.pdf;*.rar;*.txt',
                'height'         : 24,   
            'width'          : 180,
                'buttonImg'     : 'images/jqueryUpload/picture.jpg',
                'wmode'          : 'transparent',   
                onSelect         : function (event, queueID,fileObj){
                 if(fileObj.size>1024*1024*100){
                    alert("文件大小不能超出100MB!");
                   }
                 },
                
                onComplete       : function (event, queueID, fileObj, response, data){    
                       alert("文件上传成功!"); 
                       //上传成功后刷新一下文件列表
                       $("#divID").load("bidUploadOrDown_getUpSuccessFileName.action",{"tender.id":${tender.id},"random":Math.random()});
                       
                       },    
                onError          : function(event, queueID, fileObj){ 
                   alert("文件上传失败!");
                   } 
              });   
        });
       </script>
</head>  <body>
<table>
<tr>
<td>
技术标:
<input type="file" name="file" id="file1" value=""/>
<a href="javascript:void(0)"  onclick="fileUpload()">上传</a>&nbsp; </td>
</tr>
</table>
<div id="divID">
     <c:if  test="${not empty requestScope.bidFielList}">
         <c:forEach items="${requestScope.bidFielList}" var="bidFile">
                <span style="color: olive;">
                  ${bidFile.filename}
                  <a href="javaScript:void(0)" onclick="dleteBidFile(${tender.id},${tender.projectid}, '${bidFile.filename}')">删除文件</a>
                </span>
                </br>   
             </c:forEach>  
        </c:if>
</div>
<div>
   上传完成后可点击<a href="bidUploadOrDown_previewBidDocument.action?tender.id=${tender.id}&tender.projectid=${tender.projectid}">下一步</a>进行确认 
</div>
</div>
</body> 
</html>
这样传到struts2的actin里面:
action 就是一大推的业务操作大体如下:   public String uploadBidDocument() throws IOException {

String bidDocumentType = super.getRequest().getParameter(
"bidDocumentType");
// 上传文件
if (file != null) {
try {
fileFileName = bidFileServiceImpl.transformFileName(
bidDocumentType, fileFileName, sysUser);
bidFile.setUserid(sysUser.getId());
bidFile.setCompanyid(sysUser.getCompanyid());
bidFile.setFilename(fileFileName);
bid.setTenderid(bidFile.getTenderid());
bid.setProjectid(bidFile.getProjectid());
bid.setBidtime(new Date());
bid.setUserid(sysUser.getId()); String filePatch = bidFileServiceImpl.uploadBidDocument(
bidFile, bid, file, fileFileName); if (Commons.NOT_ALLOW_UPLOAD_AGAIN.equals(filePatch)) {
//如果是上传相同的一个文件吗,提示不能重复上传
setAttribute("uploadMessage",getText("InviteBid.NOT_ALLOW_UPLOAD_AGAIN"));
     
} else {
setAttribute("uploadMessage",
getText("InviteBid.UPLOAD_SUCCESS"));
setAttribute("isAppSpan", "true");
setAttribute("filePath", filePatch);
}
}
} catch (Exception e) {
// 可记录日志
e.printStackTrace();
setAttribute("uploadMessage", getText("InviteBid.UPLOAD_FAIL"));
}
} else {
                          //请选择一个要上传的文件
setAttribute("uploadMessage",
getText("InviteBid.PLEASE_SELECT_UPLOAD_FILE"));
}
setAttribute("bidDocumentType", bidDocumentType);
  return "uploadIframe";
}
问题描述:
jquery的这个插件好像是异步上传的!我想在其上传前检查一下要上传的这个文件是否已经上传过了。
如果上传过了就提示一下alert(“同一个文件只能上传一次!”)然后,不让去上传(终止掉其本次上传)找了好久也没找到这个插件有什么方法可以在上传前检查这个文件是不是上传过了。
第二又如何终止掉其继续上传呢(有可能你说上传过了,不能再上传了,但是什么都不处理的话,还是会上传的)struts2jquery插件异步文件上传