首先是web
<?xml version=
<!DOCTYPE web
<web
<servlet>
<servlet
<servlet
<init
<param
<param
</init
<load
</servlet>
<servlet
<servlet
<url
</servlet
</web
然後是struts
<?xml version=
<!DOCTYPE struts
<struts
<data
<form
<form
</form
<global
<global
<action
<action
attribute=
name=
path=
scope=
type=
validate=
</action
<message
</struts
然後是頁面test
<%@ page language=
<%@ taglib uri=
<%@ taglib uri=
<%@ taglib uri=
<%@ taglib uri=
<!DOCTYPE HTML PUBLIC
<html:html>
<head>
<title>
multiUploadDemo
</title>
<script language=
var num =
function upload(){
document
multiUploadForm
}
function additem(id)
{
var row
row = eval(
if(row != null )
{
cell = row
str=
cell
}
num++;
}
function deleteitem(obj
{
var rowNum
curRow = obj
rowNum = eval(
eval(
}
function callback(msg)
{
document
}
</script>
<body bgcolor=
<div id=
<html:form method=
<table id=
</table>
</html:form>
<iframe name=
<input type=
<input type=
</body>
</html:html>
下面是FORM和ACTION
我把下面
UploadFile
package com
import java
import org
public class UploadFile implements Serializable {
private FormFile file;
public FormFile getFile() {
System
return file;
}
public void setFile(FormFile file) {
this
}
}
MultiUploadForm
package com
import java
import java
import org
import com
public class MultiUploadForm extends ActionForm {
private List myFiles;
public MultiUploadForm(){
myFiles = new ArrayList();
myFiles
}
public List getMyFiles() {
return myFiles;
}
//注意這個方法的定義 不加中間的循環是會出錯的
public UploadFile getUploadFile(int index){
int size = myFiles
if(index>size
for(int i=
myFiles
}
}
return (UploadFile)myFiles
}
public void setMyFiles(List myFiles) {
this
}
}
最後是action
package com
import java
import java
import java
import javax
import javax
import org
import org
import org
import org
import org
public class MultiUploadAction extends Action {
public ActionForward execute(ActionMapping mapping
HttpServletRequest request
MultiUploadForm multiUploadForm = (MultiUploadForm) form;
List myFiles = multiUploadForm
String fileStr =
for (int i =
UploadFile uploadFile = (UploadFile) myFiles
FormFile file = uploadFile
if (file == null) {
System
} else {
// 能運行到這裡
System
System
fileStr +=
+ file
}
}
// 返回文本
try {
response
PrintWriter out = response
out
+
} catch (IOException e) {
e
}
return null;
}
}
這個是我從現在寫好的裡截取的一部分
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28228.html