uploadify3.0 与 struts2结合

		$("input[id][id^='file_']").each(function(i,obj) {
			$(obj).uploadify({
				'langFile'		: '${ctx}/static/js/jquery-uploadify/uploadifyLang_zh.js',
				'swf'      		: '${ctx}/static/js/jquery-uploadify/uploadify.swf',
				'uploader'		: '${ctx}/powerword/powerword_ajaxUpload.do',//servlet的路径或者.jsp 这是访问servlet 'scripts/uploadif' 
				'method'         : 'get',
				'postData'		: {'id':'${powerword.id}','audioId':''+$(obj).attr("id")},
				'fileObjName'   : 'uploadify',//和input的name属性值保持一致就好,Struts2就能处理了   
				'cancelImage'    : '${ctx}/static/js/jquery-uploadify/uploadify-cancel.png',
				'auto'           : true, //选定文件后是否自动上传,默认false
				'multi'          : false, //是否允许同时上传多文件,默认false
				'queueID'		: "fileList_"+$(obj).attr("id"),
				'debug'			: false,
				'removeCompleted': false,
				'requeueErrors'	: false,
				'progressData'	: "all",
				'queueSizeLimit' : 1, //限制在一次队列中的次数(可选定几个文件)。默认值= 999,而一次可传几个文件有 simUploadLimit属性决定。
				'fileSizeLimit'	: 50*1024*1024, //设置单个文件大小限制,单位为byte ,50M
				'fileTypeDesc'   : '支持格式:mp3', //如果配置了以下的'fileExt'属性,那么这个属性是必须的 
				'fileTypeExts'   : '*.mp3',//允许的格式
				onUploadSuccess : function(file,data,response) {	
				   	if(data){
				   		var mp3 = eval('(' + data + ')');
						$("#label_"+$(obj).attr("id")).text(mp3.path);
				   	}
				},
				onUploadError : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue) {
					$("#dialog-message").html(errorString);
				}
			});
		});

 

 

<input id='file_listenAudio' name='uploadify' type='file'/>

 

 

public class PowerwordAction extends Struts2BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private File uploadify;
                private String uploadifyContentType;
                private String uploadifyFileName;

	/**
	 * 配合uploadify插件使用的上传方法。
	 *
	 * @author liwei
	 * @return
	 * @throws Exception 
	 */
	private String uploadify() throws Exception{
		
		
		
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-M-d");
		String today = df.format(date);

		String path = "/upload/audio/powerword/" + today;
		File folder = new File(ServletActionContext.getServletContext().getRealPath(path));
		String filePath = path + "/" + UUID.randomUUID().toString().replaceAll("-", "") + ".mp3";
		if (!folder.exists())
			folder.mkdirs();

		File outFile = new File(ServletActionContext.getServletContext().getRealPath(filePath));
		FileOutputStream outStream = new FileOutputStream(outFile);
		FileInputStream inStream = new FileInputStream(uploadify);
		byte[] buffer = new byte[1024];
		int l = 0;
		while ((l = inStream.read(buffer)) > 0) {
			outStream.write(buffer, 0, l);
		}
		inStream.close();
		outStream.close();

		return filePath;
	}
}

 

	<package name="powerword" extends="sessionControl">
		<action name="powerword_ajaxUpload" class="powerwordAction" method="ajaxUpload">
			<interceptor-ref name="fileUpload">
				<param name="maximumSize">102400000</param>
				<param name="allowedTypes">audio/mp3,application/octet-stream</param>
			</interceptor-ref>
			<interceptor-ref name="sessionStack"/>
		</action>
	</package>

 

 

	<filter>
		<filter-name>struts2Filter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2Filter</filter-name>
		<url-pattern>*.do</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>

	<filter-mapping>
		<filter-name>struts2Filter</filter-name>
		<url-pattern>*.jsp</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>

 

 

一开始查了N多资料没有对3.0的文章,3.0与2.0+不一样的地方就是fileObjName这个属性的名字换了

还有可能我的struts2的配置跟网上的不太一样,最后调试了很长时间才调试通过

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Viggo.Lee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值