日期:2014-05-16  浏览次数:20421 次

ExtJS 上传后 下载提示的处理
1.首先是Struts.xml的配置
<action name="uploadexc" method="uploadExcel" class="com.maixin.code.action.UserWorkTimeAction" >   
			<interceptor-ref name ="fileUploadStack" >
				<!-- <param name="allowedTypes">xls,xlsx</param>  --> 
				<param name="maximumSize">20000000000</param> 
			</interceptor-ref> 
			<result type='json'>
				<param name="contentType">text/html</param>  
				<param name="excludeProperties">upload,userWorkTimeSer</param>
			</result>
		</action>   

2.action的写法
	/**
	 * 上传Excel
	 * @return
	 */
	public String uploadExcel(){
		try {
			Date d = new Date();  
	        System.out.println("uploadFileName = "+this.uploadFileName);  
	        //upload --  wapps 下面的文件夹,用来存放图片  
	        String toSrc = ServletActionContext.getServletContext().getRealPath("upload")+"/"+d.getTime()+getFileExp(this.uploadFileName);  //使用時間戳作為文件名  
	        System.out.println("toFile= "+toSrc);  
	        File toFile = new File(toSrc);  
	        writeFile(this.upload,toFile);  
	        userWorkTimeSer.saveExcelWorkTime(upload);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return SUCCESS;  
	}

2.JS的写法
this.uploadform.getForm().submit({
						url: 'uploadexc.action',
						//waitMsg: 'Uploading your photo...',
						success: function(response){

						},
						failure:function(response){
							//上传完后,返回失败,
							Ext.getCmp('upwindow').hide();
							Ext.getCmp('userWorkTimeGrid').getStore().reload();
						}
					
             		});

在Struts2 中,上传完成后,返回的JSON时,提示下载,用上面的配置后,不会提示了,Ajax返回的居然是failure,很是奇怪,使用fileBug查看也是正常的,不过算是解决了!呵呵