apache fileupload 组件问题 在线等 急!!!
#### servlet:UploadImage.java #######
package com.nic;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import org.apache.commons.fileupload.*;
public class UploadImage extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
// Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
//PrintWriter out = response.getWriter();
try {
String file_name;
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
upload.setSizeMax(3*102400);
//maximum size that will be stored in memory?
// 设置最多只允许在内存中存储的数据,单位:字节
//upload.setSizeThreshold(4096);
// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
upload.setRepositoryPath("d:\\temp");
//开始读取上传信息
Iterator iter = items.iterator();
FileItem item;
while (iter.hasNext()) {
item = (FileItem) iter.next();
if (item.isFormField()) {
//
} else {
//取文件本地路径加文件名
String itemName = item.getName();
file_name = itemName.substring(itemName.lastIndexOf("\\")+1);
file_name = "D:\\" + file_name;
// out.println(file_name);
File newFile = new File(file_name);
if (newFile.exists()) {
//
}
else {
newFile.createNewFile();
item.write(newFile);
}
}
}
} catch (Exception e) {
System.out.println("上传出错:"+e);
}
}
}
##### upload.html #####
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>文件上传演示</h1>
<form name="uploadform" method="POST" action="Test1" enctype="multipart/form-data">
<table border="1" width="450" cellpadding="4" cellspacing="2"
bordercolor="#9BD7FF">
<tr>
<td width="100%" colspan="2">文件1:<input name="x" size="40"
type="file"></td>
</tr>
<tr>
<td width="100%" colspan="2">文件2:<input name="y" size="40"
type="file"></td>
</tr>
<tr>
<td width="100%" colspan="2">文件3:<input name="z" size="40"
type="fil