web
<web
xmlns=
xmlns:xsi=
xsi:schemaLocation=
<filter>
<filter
<filter
</filter>
<filter
<filter
<url
</filter
</web
struts
<?xml version=
<!DOCTYPE struts PUBLIC
<struts>
<package name=
<action name=
<result name=
</action>
</package>
</struts>
upload
<%
pageEncoding=
<%
<html>
<head>
<title>upload</title>
</head>
<body>
<s:form action=
<s:textfield name=
<s:file name=
<s:submit/>
</s:form>
</body>
</html>
result
<%
pageEncoding=
<%
<html>
<head>
<title>result</title>
</head>
<body>
<s:property value=
<br>
<s:property value=
</body>
</html>
UploadAction
package com
import java
import java
import java
import java
import java
import org
import com
public class UploadAction extends ActionSupport
private String username;
private File file;
private String fileFileName; // 有屬性file+Filename固定組成
private String fileContentType; // 有屬性file+ContentType固定組成
public String getUsername()
return username;
}
public void setUsername(String username)
this
}
public File getFile()
return file;
}
public void setFile(File file)
this
}
public String getFileFileName()
return fileFileName;
}
public void setFileFileName(String fileFileName)
this
}
public String getFileContentType()
return fileContentType;
}
public void setFileContentType(String fileContentType)
this
}
@Override
public String execute() throws Exception
InputStream is = new FileInputStream(file);
String root = ServletActionContext
File destFile = new File(root
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[
int length =
while ((length
os
}
is
os
return SUCCESS;
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28582.html