piperzero 发表于 2013-1-23 01:30:10

AJAX与JSF实现带进度条的批量上传文件实例

<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog.html" frameborder="0" width="728" scrolling="no" height="90"></iframe><div class="postText">一。NetBeans 5.5.1 中的样例:


在NetBeans 5.5.1中自带了一个“文件上载“的例子,使用这个例子,请先下载并安装以下软件:

[*]    JAVA SE 5 (JDK 1.5) 及以上版本(http://java.sun.com/javase/downloads/index.jsp )
   
[*]    NetBeans 5.5.1(http://zh-cn.netbeans.org/index_zh_CN.html )
   
[*]    Sun Application Server 9.0(https://glassfish.dev.java.net/)
   
2+3也可以下载“NetBeans IDE 5.5.1 with Java EE Application Server 9.0 U1 Patch 1 bundle ”(http://www.netbeans.info/downloads/index.php?rs=22&p=3)


在NetBeans中,选择菜单“新建项目”-〉“类别”中选择“样例”-〉“Java BluePrint Solution” ->AJAX编程模型。项目中选择“文件上载”。项目名缺省为“fileupload”


运行项目“fileupload”, 并且选择几个上传文件,文件类型可以多种多样,比如pdf, jar, ra, zip, jpeg, gif等等。可以看到如下界面。
http://p.blog.csdn.net/images/p_blog_csdn_net/adali/330776/o_upload_progress.JPG
传输完毕,可以看到如下结果。
http://p.blog.csdn.net/images/p_blog_csdn_net/adali/330776/o_upload_result.JPG


显示了上传文件开始,结束的的时间,上传文件总的字节数目等等。


项目“fileupload”的/web/docs/下有一个fileupload.html 的文档,解释了这个上传文件的参数及使用(English)。文件上载是一个JSF控件,开发者需要了解的除了如何在服务器端处理请求中的参数,如何在客户端显示响应信息外,所需要了解的仅仅是一些参数的设置。如这个例子中的代码所示:
            <fileuploadtag>id="TestFileuploadForm0" <strong>retFunction</strong>="testRetFunction" <strong>retMimeType</strong>="text/xml" </fileuploadtag>
            postProcessingMethod="#{FileUploadCustomBean.postProcessingMethod}"
            progressBarDivId="progress1x" progressBarSubmitId="submit1x" progressBarSize="40">
页: [1]
查看完整版本: AJAX与JSF实现带进度条的批量上传文件实例