现在的位置: 首页 > 综合 > 正文

apache commons-fileupload 组件实现上传

2013年10月05日 ⁄ 综合 ⁄ 共 772字 ⁄ 字号 评论关闭

http://commons.apache.org/fileupload/using.html

使用该组件的例子:

<%@ page language=“java”contentType=“text/html;charset=GBK”%>
<%@ page import=“java.util.*”%>
<%@ page import=“org.apache.commons.fileupload.*”%>
<html>
<head>
<title>文件上传</title>
</head>
<%
 DiskFileUpload fu = new DiskFileUpload();
 // 设置允许用户上传文件大小,单位:字节
 fu.setSizeMax(10000000);
 // 设置最多只允许在内存中存储的数据,单位:字节
 fu.setSizeThreshold(4096);
 // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
 fu.setRepositoryPath(“D://Tomcat5//TEMP”);
 //开始读取上传信息
 List fileItems = fu.parseRequest(request);
 // 依次处理每个上传的文件
 Iterator iter = fileItems.iterator();
 while (iter.hasNext()) {
  FileItem item = (FileItem) iter.next();
  //忽略其他不是文件域的所有表单信息
  if (!item.isFormField()) {
   String name = item.getName();
   item.write(“D://UploadTest//”+ name);
 }
}
%>

引用自:http://bluelzx.javaeye.com/blog/195259

抱歉!评论已关闭.