jquery uploadify +struts2上传文件的问题?

阿诺 阿诺 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我描述一下,就是使用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>  </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(“同一个文件只能上传一次!”)然后,不让去上传(终止掉其本次上传)

找了好久也没找到这个插件有什么方法可以在上传前检查这个文件是不是上传过了。
第二又如何终止掉其继续上传呢(有可能你说上传过了,不能再上传了,但是什么都不处理的话,还是会上传的)
...全文

相关推荐

jQuery uploadify上传文件(JAVA版+Struts2即时预览效果)

官网上是PHP版的,想找个JAVA版的不容易啊,终于被我搞出来了,并且解决了中文乱码问题,里边有源代码和帮助文档,非常易学

阿轮_

jquery+uploadify + struts2 + jsp 图片批量上传Demo

jquery+uploady+struts 实现图片上传

huangshan1101

struts2+ajax+jquery异步批量上传超大文件

struts2+ajax+jquery异步批量上传超大文件,单文件最大支持2G,一次文件数量,文件大小都可设置。简单明了。绝对可用,稍微懂点的就可以修改为自己所用。你值得拥有! 我会分享给大家更多更好的东西,希望支持!

zhouss135ss_june

struts2 +jquey uploadify3.2 实现多文件上传

struts2 +jquey uploadify3 2 实现多文件上传 可以运行的myeclipse工程 绝对好用 访问方式http: 127 0 0 1:8080 Struts2Uploadify upload jsp uploadify 使用说明: &lt;a href &quot;javascript:$ &quot;#file upload&quot; uploadify &quot;cancel&quot; &quot;&gt;取消列队中的第一个文件上传&lt; a&gt; &lt;a href &quot;javascript:$ &quot;#file upload&quot; uploadify &quot;cancel&quot; &quot; &quot; &quot;&gt;取消所有列队中的文件上传&lt; a&gt; 语法: uploadify &quot;cancel&quot; &quot;fileID&quot; &quot;suppressEvent&quot; 将调用方法cancel 接受两个参数: fileID:要取消的列队文件id 不传递参数时 表示取消列队中的第一个文件上传 传递星号 表示取消列队中的所有文件上传 suppressEvent:设置为true将禁止onUploadCancel事件 取值:String &quot;true&quot;|&quot;事件名&quot;">struts2 +jquey uploadify3 2 实现多文件上传 可以运行的myeclipse工程 绝对好用 访问方式http: 127 0 0 1:8080 Struts2Uploadify upload jsp uploadify 使用说明: &lt;a href &quot;javascript:$ &quot;#file upload&quot; uploadify &quot;cancel&quot; &quot;&gt;取消列队中的 [更多]

JIESA

Struts2+uploadify上传文件

struts2 + uploadify上传文件示例

shiguifengjin
评论 1
收藏 已收藏
分享
返回顶部
阿诺
Java EE 67,535 成员 225,843 内容