概述
http://blog.csdn.net/lishehe/article/details/36230155
http://blog.csdn.net/kuaileren003/article/details/8525020
jsp:
<script type="text/javascript">
$("document").ready(function() {
//清空之前文件上传个数
$("#muscic_upLoad").click(function(){
$("#music_num").empty();
});
});
//每个文件上传返回函数
function onUploadSuccess(file, data, response){
// alert('文件[' + file.name + ']上传成功了,' + response + '返回值:' + data);
if(response){
$("#shownode").append("<p>已成功上传"+file.name+"文件</p>");
}
}
//所有文件上传返回函数
function onQueueComplete(queueData){
//alert(queueData.uploadsSuccessful + ' 个文件上传成功!');
$("#shownode").append("<p id='music_num'>已成功上传"+queueData.uploadsSuccessful+"个文件</p>");
}
//清空上传文件
function notUpLoad(){
$("#fileQueue").empty();
return;
}
</script>
<div class="pageContent" style="margin: 0 10px" layoutH="50">
<form method="post" action="musicUpdate/musicUpdate_upLoad.action"
enctype="multipart/form-data" οnsubmit="return iframeCallback(this);">
<input id="musicUpdate" type="file" name="music"
uploaderOption="{
swf:'uploadify/scripts/uploadify.swf',
uploader:'musicUpdate/musicUpdate_upLoad.action',
formData:{},
fileObjName:'music',
fileSizeLimit:'200KB',
fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;',
fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;',
queueID:'fileQueue',
buttonImage:'uploadify/img/add.jpg',
buttonClass:'my-uploadify-button',
width:102,
auto:false,
'onUploadSuccess' :onUploadSuccess,
'onQueueComplete' :onQueueComplete
}" />
<div id="fileQueue" class="fileQueue"></div>
<input type="image" src="uploadify/img/upload.jpg" id="muscic_upLoad"
οnclick="$('#musicUpdate').uploadify('upload', '*');" />
<input type="image" src="uploadify/img/cancel.jpg"
οnclick="notUpLoad();" />
</form>
<div id="shownode" ></div>
<div class="divider"></div>
</div>
action:
package com.zdaq.musicUpdate.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.struts2.ServletActionContext;
import com.zdaq.common.action.BaseAction;
public class MusicUpdateAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = -1820020948168948317L;
// 表单提交后返回页面的参数
public String statusCode;
public String message;
public String navTabId;
public String rel;
public String callbackType;
public String forwardUrl;
// 参数
private File music; // 上传的文件
private String musicFileName; // 文件名称
private String musicContentType; // 文件类型
private String savePath = "/musicUpdate";// 接受依赖注入的属性
// 文件上传
public String upLoad() {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
if (music == null) {
message = "文件没被上传";
return "upLoad";
}
fos = new FileOutputStream(getSavePath() + "\"+ getMusicFileName());
// 建立文件上传流
fis = new FileInputStream(getMusic());
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
message = "文件上传成功";
} catch (Exception e) {
e.printStackTrace();
message = "文件上传失败";
return "error";
}
return "upLoad";
}
struts.xml
<action name="musicUpdate_*" class="com.zdaq.musicUpdate.action.MusicUpdateAction" method="{1}">
<result name="upLoad" type="json">
<param name="root">message</param>
</result>
</action>
最后
以上就是烂漫鸡翅为你收集整理的dwz多文件上传的全部内容,希望文章能够帮你解决dwz多文件上传所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复