/*
* 处理附件上传的通知。
* 各位可以继承这个类,来实现自己的特殊处理。
*
* @author 赵学庆 www.java2000.net
*/
public class UploadListener ... {
// 调试模式将在控制台打印出一些数据
private boolean debug;
// 总数据字节数
private int total;
// 当前已经处理的数据字节数
private int totalCurrent = 0 ;
// 延迟,用来调试用,免得速度太快,根本卡看不到进度
private int delay = 0 ;
/** */ /**
* 处理数据通知的方法。
* 保存已经处理的数据。并且在一定的比例进行延迟。默认每1%
* 如果不需用延迟,可以删掉内部的代码,加快速度。
*
* @param size 增加的字节数
*/
public void increaseTotalCurrent( long size) ... {
this .totalCurrent += size;
try ... {
currentRate = totalCurrent * 100 / total;
if (currentRate > lastRate) ... {
if (delay > 0 ) ... {
Thread.sleep(delay);
}
if (debug) ... {
System.out.println( " rate= " + totalCurrent + " / " + total + " / " + (totalCurrent * 100 / total));
}
lastRate = currentRate;
}
} catch (Exception e) ... {
e.printStackTrace();
}
}
/** */ /**
* 读取全部自己数
*
* @return
*/
public int getTotal() ... {
return total;
}
/** */ /**
* 读取已经处理的字节数
*
* @return
*/
public int getTotalCurrent() ... {
return totalCurrent;
}
private long lastRate = 0 ;
private long currentRate = 0 ;
public int getDelay() ... {
return delay;
}
public void setDelay( int delay) ... {
this .delay = delay;
}
public void setTotal( int total) ... {
this .total = total;
}
public boolean isDebug() ... {
return debug;
}
public void setDebug( boolean debug) ... {
this .debug = debug;
}
}
Upload upload = new Upload(request); // 增加了侦听进度的代码 UploadListener uploadListener = new UploadListener(); // 这句话我们后面再讨论,这个可是关键 session.setAttribute( " uploadListener " ,uploadListener); uploadListener.setDelay( 0 ); uploadListener.setDebug( true ); upload.setUploadListener(uploadListener); upload.parse(); // 这句话同样重要,我们后面再讨论 session.setAttribute( " uploadListener " , null );
< script. type = " text/javascript. " >
function checkForm() ... {
$( " SHOW_FRAME. " ).src = " link.jsp " ;
$( ' SUBMIT ' ).disabled = true ;
Ext.MessageBox.show( ... {
title: ' Please wait... ' ,
msg: ' Initializing... ' ,
width: 240 ,
progress: true ,
closable: false
} );
$( " MAIN_FORM. " ).submit();
return false ;
}
function setUploadProcess(total,current) ... {
var rate = Number(current) / Number(total);
Ext.MessageBox.updateProgress(rate, ' Uploading... ' + current + " / " + total);
if (Number(current) >= Number(total)) ... {
closeUploadProcess();
}
}
function closeUploadProcess() ... {
Ext.MessageBox.hide();
}
</ script. >
< iframe. name = " ACTION_FRAME. " id = " ACTION_FRAME. " width = " 0 " height = " 0 " ></ iframe. >
< iframe. name = " SHOW_FRAME. " id = " SHOW_FRAME. " width = " 0 " height = " 0 " ></ iframe. >
< form. method = " OST " id = " MAIN_FORM. " nsubmit = " return checkForm() " enctype = " multipart/form-data "
action = " uploadFileSave.jsp " target = " ACTION_FRAME. " >
< input type = " file " size = " 50 " name = " file " >
< input type = " submit " ID = " SUBMIT " value = " Upload It " >
</ form. >
<% @ page language = " java " contentType = " text/html; charset=utf-8 " pageEncoding = " utf-8 " %>
<% @include file = " ../package.inc.jsp " %>
<%
response.setHeader( " ragma " , " no-cache " );
response.setHeader( " Cache-Control " , " no-cache " );
response.setDateHeader( " Expires " , 0 );
response.setBufferSize( 0 );
UploadListener uploadListener = null ;
while (uploadListener == null || uploadListener.getTotalCurrent() <= 0 ) ... {
uploadListener = (UploadListener) session.getAttribute( " uploadListener " );
out.print( " . " );
out.flush();
Thread.sleep( 10 );
}
long total = uploadListener.getTotal();
out.println(total);
long current;
out.flush();
while ( true ) ... {
current = uploadListener.getTotalCurrent();
if (current >= total) ... {
break ;
}
out.println( " <script. type='text/javascript'>parent.setUploadProcess(' " + total + " ',' " + current + " ');</script> " );
out.flush();
Thread.sleep( 10 );
}
%>< script. type = " text/javascript. " > parent.closeUploadProcess(); </ script. >
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有