为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > AJAX实现进度条

AJAX实现进度条

2018-02-23 5页 doc 17KB 9阅读

用户头像

is_337177

暂无简介

举报
AJAX实现进度条AJAX实现进度条 public class UploadListener implements OutputStreamListener { private HttpServletRequest request; private long delay = 0; private long startTime = 0; private int totalToRead = 0; private int totalBytesRead = 0; private int totalFiles = -1; public ...
AJAX实现进度条
AJAX实现进度条 public class UploadListener implements OutputStreamListener { private HttpServletRequest request; private long delay = 0; private long startTime = 0; private int totalToRead = 0; private int totalBytesRead = 0; private int totalFiles = -1; public UploadListener(HttpServletRequest request, long debugDelay) { this.request = request; this.delay = debugDelay; totalToRead = request.getContentLength(); this.startTime = System.currentTimeMillis(); } public void start() { totalFiles ++; updateUploadInfo("start"); } public void bytesRead(int bytesRead) { totalBytesRead = totalBytesRead + bytesRead; updateUploadInfo("progress"); try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } public void error(String message) { updateUploadInfo("error"); } public void done() { updateUploadInfo("done"); } private long getDelta() { return (System.currentTimeMillis() - startTime) / 1000; } private void updateUploadInfo(String status) { long delta = (System.currentTimeMillis() - startTime) / 1000; request.getSession().setAttribute("uploadInfo", new UploadInfo(totalFiles, totalToRead, totalBytesRead,delta,status)); } } ÉÏÃæµÄ?úÂëÖÐ??Ô,×?ÕßΪÁËÑÝÊ????ú?Ù×?ÉϵÄÏÔÊ?Ð??û??ÌØ?ð?ÓÈëÁËdebugDelay×öÑÓÊ???Àí??ÔÚʵ?ÊÓ?ÓÃÖÐ?ÉÒÔÉ??ý?? upload.jsp: <%@ page import="be.telio.mediastore.ui.upload.MonitoredDiskFileItemFactory" %> <%@ page import="be.telio.mediastore.ui.upload.UploadListener" %> <%@ page import="org.apache.commons.fileupload.FileItem" %> <%@ page import="org.apache.commons.fileupload.FileItemFactory" %> <%@ page import="org.apache.commons.fileupload.FileUploadException" %> <%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%-- /* Licence: * Use this however/wherever you like, just don't blame me if it breaks anything. * * Credit: * If you're nice, you'll leave this bit: * * Class by Pierre-Alexandre Losson -- * email : plosson@users.sourceforge.net */ --%> <% UploadListener listener = new UploadListener(request, 30); // Create a factory for disk-based file items FileItemFactory factory = new MonitoredDiskFileItemFactory(listener); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); try { // process uploads .. upload.parseRequest(request); //....??ÀíÉÏ??ÎÄ?þ } catch (FileUploadException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } %>
/
本文档为【AJAX实现进度条】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索