这里给出了自己写的一个使用struts upload包 进行文件上传的例子。
测试环境再 Tomcat 5.0.12,servlet 2.3,jsp 1.2,structs 1.1通过。

1。FileLoadAction
//-----------------------------FileLoadAction code ---------------------------------------
package structs_file_test;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import org.apache.struts.upload.*;
import java.util.Hashtable;
import java.util.Collection;
import java.util.Iterator;
import java.io.*;

public class FileLoadAction extends Action {
private static final String FILE_SAVE_PATH="e:/";
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {

FileLoadActionForm theForm = (FileLoadActionForm) actionForm;
//获得上传文件信息
FormFile file1 = theForm.getFile1();
FormFile file2 = theForm.getFile2();

//设置文件保存的位置
String sSaveFilePath= FILE_SAVE_PATH;// servletRequest.getServletPath();
System.out.println("SaveFilePath=" + sSaveFilePath);

// file1.getFileName()获得文件的名字, 没有包含文件path 信息
System.out.println("file1 ,filename=" + file1.getFileName());
System.out.println("file2 ,filename=" + file2.getFileName());

//可以把文件描述信息保存起来,保存到文件或者数据库
//theForm.getFile1_desc();
//theForm.getFile2_desc();

InputStream in = null;
try {
in = file1.getInputStream();
//saveToFile(in, "e:/1.txt");//for test
saveToFile(in, sSaveFilePath + file1.getFileName());
} catch (Exception ex) {
System.err.println("error,save first file fail!");
}
try {
in = file2.getInputStream();
// saveToFile(in, "e:/2.txt");//for test
saveToFile(in, sSaveFilePath + file2.getFileName());
} catch (Exception ex) {
System.err.println("error,save second file fail!");
}
return actionMapping.findForward("home");
}
private void saveToFile(InputStream in, String sFileName) {
FileOutputStream out;
//这里可以保存倒数据库或者磁盘
try {
out = new FileOutputStream(sFileName);
byte b[] = new byte[1024];
int i = 0;
while ((i = in.read(b)) > 0) {
out.write(b, 0, i - 1);
}
out.close();
} catch (Exception ex) {
System.err.println("save file=" + sFileName + " fail!" +
ex.getMessage());
}
}
}
//---------------------------------end FileLoadAction -----------------------------------------------
2.FileLoadActionForm
//---------------------FileLoadActionForm code ----------------------------------
package structs_file_test;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author [email protected]
* @version 1.0
*/
public class FileLoadActionForm extends ActionForm {
/**
* 对应fileLoadjsp.jsp 的 <input align="left" type="file" name="file1" tabindex="0">
* 注意类型是FormFile
* */
private FormFile file1;
private String file1_desc;
/**
*对应fileLoadjsp.jsp 的 <input align="left" type="file" name="file2" tabindex="2">
* 注意类型是FormFile
* */
private FormFile file2;
private String file2_desc;
public FormFile getFile1() {
return file1;
}
public void setFile1(FormFile file1) {
this.file1 = file1;
}
public void setFile2_desc(String file2_desc) {
this.file2_desc = file2_desc;
}
public void setFile2(FormFile file2) {
this.file2 = file2;
}
public void setFile1_desc(String file1_desc) {
this.file1_desc = file1_desc;
}
public String getFile1_desc() {
return file1_desc;
}
public FormFile getFile2() {
return file2;
}
public String getFile2_desc() {
return file2_desc;
}
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
/** @todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping,
HttpServletRequest servletRequest) {
}
}

//---------------------end FileLoadActionForm code ----------------------------------
3. struts-config.xml
//---------------------------------------------struts-config.xml --------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="fileLoadActionForm" type="structs_file_test.FileLoadActionForm" />
</form-beans>
<action-mappings>
<action input="/fileLoadjsp.jsp" name="fileLoadActionForm" path="/fileLoadAction" scope="request" type="structs_file_test.FileLoadAction" validate="true">
<forward contextRelative="true" name="home" path="/welcome.jsp" redirect="true" />
</action>
</action-mappings>
</struts-config>
//---------------------------------------------end struts-config.xml --------------
4.web.xml
//------------------------------------- web.xml -----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>WebModule1</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
//-------------------------------------end web.xml -----------------------------------
5.fileLoadjsp.jsp
//---------------------------------------- fileLoadjsp.jsp --------------
<%@page contentType="text/html; charset=GB2312"%>
<html>
<head>
<title>fileLoadjsp</title>
</head>
<body bgcolor="#ffffff">
<h1>structs file load example</h1>
<form name="filelaod" action="/fileLoadAction.do" method="POST" enctype="multipart/form-data">
<p>the first file &nbsp;
<input align="left" type="file" name="file1" tabindex="0">
</p>
<p><br>
文件1的描述 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input align="left" type="text" name="file1_desc" tabindex="1">
<br>
</p>
<p><br>
the second file&nbsp;
<input align="left" type="file" name="file2" tabindex="2">
</p>
<p><br>
文件2的描述 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input align="left" type="text" name="file2_desc" tabindex="3">
</p>
<p><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="ok" value="提 交">
</p>
</form>
<br>
<br>
<a href="welcome.jsp" tabindex="4">goto home</a>
</body>
</html>
//----------------------------------------end fileLoadjsp.jsp --------------
6.welcome.jsp
//------------------------------------------------------welcome.jsp ----------------------------
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>
welcome
</title>
</head>
<body bgcolor="#ffffff">
<h1>
for test structs file load
</h1>
<a href="fileLoadjsp.jsp"> goto file load page </a>
</body>
</html>