可以限制文件大小,类型,支持中文,多文件上传,并且可以存到指定目录
直接上代码,有问题直接提
<?xml version="1.0" encoding="GBK"?>
<window>
<label value="test"></label>
<button label="upload">
<attribute name="onClick">
<![CDATA[
import org.zkoss.zk.ui.util.Configuration;
import java.io.*;
import org.zkoss.io.Files;
Desktop desktop = self.getDesktop();
Configuration conf = desktop.getWebApp().getConfiguration();
conf.setMaxUploadSize(1024);
//解决中文问题,如果上传的文件中有中文
conf.setUploadCharset("gbk");
//如果文本文件的话,返回的实际是AMedia类型
Object media = Fileupload.get();
//多文件
//Object[] mediaArray = Fileupload.get(5);
if(media!=null){
String fileName = media.getName();
if(!fileName.endsWith(".txt")){
alert("not a txt file");
return;
}
/**
* 用Reader的方式,实际是StringReader
*/
Reader r = media.getReaderData();
File f = new File("c:\\temp\\"+fileName);
/*
//可以获得相对路径
File f = new File(Executions.getCurrent().getDesktop().getWebApp().getRealPath("medias") + "/"+ media.getName());
*/
if(!f.exists()){
f.createNewFile();
}
//Files类是由ZK提供的
Files.copy(f,r,null);
Files.close(r);
/*
//用InputStream的实现方式
InputStream ins = new ByteArrayInputStream(media.getStringData().getBytes());
File f = new File("c:\\temp\\"+fileName);
if(!f.exists()){
f.createNewFile();
}
OutputStream out = new FileOutputStream(f);
byte[] buf=new byte[1024];
int len;
while((len=ins.read(buf))>0){
out.write(buf,0,len);
}
out.close();
ins.close();
*/
alert("file created");
}
//alert(media.getStringData().length());
//alert(media.getName());
]]>
</attribute>
</button>
<vbox id="file">
</vbox>
</window>
<window title="Fileupload Demo" border="normal">
<image id="image"/>
<button label="Upload">
<attribute name="onClick">{
Object media = Fileupload.get();
if (media instanceof org.zkoss.image.Image)
image.setContent(media);
else if (media != null)
Messagebox.show("Not an image: "+media, "Error",
Messagebox.OK, Messagebox.ERROR);
}
</attribute>
</button>
</window>
<window title="fileupload demo" border="normal">
<button label="Upload">
<attribute name="onClick"><![CDATA[{
Object media = Fileupload.get(5);
if (media != null)
for (int j = 0; j < media.length; ++j) {
if (media[j] instanceof org.zkoss.image.Image) {
Image image = new Image();
image.setContent(media[j]);
image.setParent(pics);
} else if (media[j] != null) {
Messagebox.show("Not an image: "+media[j], "Error",
Messagebox.OK, Messagebox.ERROR);
}
}
}]]>
</attribute>
</button>
<vbox id="pics"/>
</window>
分享到:
相关推荐
开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2...
commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-...
赠送jar包:commons-fileupload-1.4.jar; 赠送原API文档:commons-fileupload-1.4-javadoc.jar; 赠送源代码:commons-fileupload-1.4-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.4.pom; 包含...
赠送jar包:commons-fileupload-1.3.3.jar; 赠送原API文档:commons-fileupload-1.3.3-javadoc.jar; 赠送源代码:commons-fileupload-1.3.3-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.3.3.pom;...
FileUpload控件的基本用法 .
commons commons-fileupload历史版本jar包集合,包括src源码 附件列表: commons-fileupload-1.0.zip commons-fileupload-1.1.1.zip commons-fileupload-1.1.zip commons-fileupload-1.2.1-bin.zip commons-...
Commons FileUpload 1.3.2. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. ...
<jsp:useBean id="myUpload" scope="page" class="fileUpload.upBean" /> //初始化工作 myUpload.initialize(pageContext); //设定允许的文件后缀名 //myUpload.setAllowedExtList("gif,jpg"); //设定允许...
commons-fileupload-1.2.1-bin commons-fileupload 文件上传 commons-fileupload-1.2.1-bin commons-fileupload 文件上传 jar包 及相关文档
FileUpload笔记FileUpload笔记FileUpload笔记FileUpload笔记FileUpload笔记FileUpload笔记
Java借助commons-fileupload组件实现文件上传所需包 Apache Commons FileUpload 1.4 (requires Java 1.6 or later) Note: This version of Commons FileUpload also requires Commons IO 2.2.
FileUpload 自带样式实在难看。 试了很多种方法,最终用了简单的css,简单美化了下。 其它思路:通过图片的click事件,触发FileUpload的click事件。但存在兼容性问题。并不能完全兼容所以浏览器。
文件上传 文件下载 FileUpload
commons-fileupload-1.2.1.jar包;commons-lang-2.3.jar,在使用组件实现文件上传时候要注意前后台的一致性,注意在后台定义File文件对象名要与jsp页面中的file标签name名字一致,前台form标签属性一定要设置为...
commons-fileupload apache开源项目,实现文件上传下载功能 ssh上传时必配
使用FileUpload组件实现上传功能,供大家一起共同分享学习。
FileUpload组件使用方法, FileUpload组件使用方法, FileUpload组件使用方法,
commons-fileupload-1.4.jar
commons-fileupload-1.3.1.jar
jsp向服务器进行文件上传所需的fileupload组件所需的jar包