RSS
热门关键字:  Linux  图形  项目管理  LAMP  java
当前位置 : 主页>开源技术>AJAX技术>列表

采用dwr ajax和struts开发文件上传进度条

来源:中国开源社区 作者:sherman 时间:2007-09-18 点击:

<div id="theMeter"> 字串8

<div id="progressBarText"></div>

字串5

<div id="progressBarBox">

字串3

<div id="progressBarBoxContent"></div>

字串1

</div>

字串4

</div> 字串2

</div> 字串9

</td>

字串1

</tr>

字串8

</table>

字串6

</form> 字串8

</body>

字串8

</html> 字串6

并且要修改一下\resources\js中的upload.js文件: 字串4

function refreshProgress()

字串5

{ 字串8

UploadMonitor.getUploadInfo(updateProgress); 字串8

} 字串6

字串4

function updateProgress(uploadInfo)

字串8

{ 字串1

if (uploadInfo.inProgress) 字串9

{ 字串5

document.getElementById('uploadbutton').disabled = true; 字串5

document.getElementById('file').disabled = true; 字串7

字串3

var fileIndex = uploadInfo.fileIndex;

字串3

字串3

var progressPercent = Math.ceil((uploadInfo.bytesRead / uploadInfo.totalSize) * 100);

字串8

字串7

document.getElementById('progressBarText').innerHTML = '文件读取进度: ' progressPercent '%'; 字串4

字串3

document.getElementById('progressBarBoxContent').style.width = parseInt(progressPercent * 3.5) 'px'; 字串3

字串1

window.setTimeout('refreshProgress()', 1000); 字串5

}

字串8

else 字串8

{

字串6

document.getElementById('uploadbutton').disabled = false; 字串1

document.getElementById('file').disabled = false; 字串4

}

字串4

字串9

return true; 字串1

} 字串1

字串9

function startProgress()

字串4

{

字串7

document.getElementById('progressBar').style.display = 'block'; 字串7

document.getElementById('progressBarText').innerHTML = '文件读取进度: 0%';

字串1

document.getElementById('uploadbutton').disabled = true;

字串1

字串5

// wait a little while to make sure the upload has started .. 字串9

window.setTimeout("refreshProgress()", 1000); 字串7

return true;

字串2

} 字串5

配置dwr.xml

字串1

放在/WEB-INF/下面

字串3

<dwr>

字串7

<allow> 字串6

<create creator="new" javascript="UploadMonitor"> 字串5

<param name="class" value="be.telio.mediastore.ui.upload.UploadMonitor"/> 字串1

</create> 字串8

<convert converter="bean" match="be.telio.mediastore.ui.upload.UploadInfo"/> 字串8

</allow>

字串9

</dwr> 字串2

web.xml中配置dwr,省略springstruts等的配置

字串6

<servlet>

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册