yucc_cau
发贴: 17
积分: 0
|
于 2005-11-01 11:28
关于文件上传Tomcat5.5.9中尽然找不到 DiskFileUpload
************* <%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%
String saveDirectory = "/home/yucc/share";
String tmpDirectory = "/home/yucc/share";
int maxPostSize = 1024 * 1024 * 1024;
%>
<%
String FileDescription = null;
String FileName = null;
long FileSize = 0;
String ContentType = null;
int count = 0 ;
%>
<%
DiskFileUpload upload = new DiskFileUpload();
upload.setSizeThreshold(4096);
upload.setSizeMax(maxPostSize);
upload.setRepositoryPath(tmpDirectory);
List /* FileItem */ items = upload.parseRequest(request);
%>
<body>
<%
Iterator iter = items.iterator();
int tmp = 0;
FileItem tmpItem = null;
while (iter.hasNext())
{
tmp++;
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
FileDescription = item.getString();
} else {
FileName = item.getName();
try {
// for wintel platform
FileName = FileName.substring(FileName.lastIndexOf("\\")+1);
// for unix-like platform
FileName = FileName.substring(FileName.lastIndexOf("/")+1);
} catch ( Exception ex ) {
out.println(ex);
}
ContentType = item.getContentType();
FileSize = item.getSize();
tmpItem = item;
}
if (tmp == 2 && FileSize != 0)
{
count ++;
%>
<font color="red">file:<%= count %></font><br>
name<%= FileName %><br>
size<%= FileSize %> Bytes<br>
type<%= ContentType %><br>
describle<%= FileDescription %><br><br>
<%
try {
out.println(FileName);
File uploadedFile = new File(saveDirectory + FileName);
tmpItem.write(uploadedFile);
} catch ( Exception ex ) {
out.println(ex);
}
tmp = 0;
} else if (tmp == 2 && FileSize == 0) {
tmp = 0;
} // end if
} // end while
%>
total <font color="red"><%= count %></font>files
</body>
</html>
********** 运行后,提示错误,找不到DiskFileUpload
tomcat5应该包含了这个类是吧,怎么回事呢
|