????????action?? ????????????
package com.oumyye.FileUpload;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadAction extends ActionSupport{
private File myFile;
private String myFileContentType;
private String myFileFileName;
private String destPath;
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
destPath = "e:/upload/";
try{
System.out.println("Src File name: " + myFile);
System.out.println("????????"+myFileFileName);
System.out.println("??????????"+ myFileContentType);
File destFile  = new File(destPath?? myFileFileName);
FileUtils.copyFile(myFile?? destFile);
}catch(IOException e){
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public File getMyFile() {
return myFile;
}
public void setMyFile(File myFile) {
this.myFile = myFile;
}
public String getMyFileContentType() {
return myFileContentType;
}
public void setMyFileContentType(String myFileContentType) {
this.myFileContentType = myFileContentType;
}
public String getMyFileFileName() {
return myFileFileName;
}
public void setMyFileFileName(String myFileFileName) {
this.myFileFileName = myFileFileName;
}
public String getDestPath() {
return destPath;
}
public void setDestPath(String destPath) {
this.destPath = destPath;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
?????????????
??????????ú?????????ó??? struts.xml????????????????????????????С?????????????????struts.xml???£?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<!-- ????????????????????????? -->
<constant name="struts.i18n.reload" value="true" />
<!-- ???????????????????????????? -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- ???????????simple -->
<constant name="struts.ui.theme" value="simple" />
<!-- ??????????????????????????????2097152(2M) -->
<constant name="struts.multipart.maxSize" value="10701096" />
<!--??????-->
<package name="upload" namespace="/" extends="struts-default">
<action name="Upload" class="com.oumyye.FileUpload.FileUploadAction">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
</action>
<!--???????-->
<action name="FileDownload" class="com.oumyye.action.FileDownload">
<result name="success" type="stream">
<param name="contentType">text/plain</param>
<param name="contentDisposition">attachment;fileName="${fileName}"</param>
<param name="inputName">downloadFile</param>
<param name="bufferSize">1024</param>
</result>
</action>
</package>
</struts>
??????????web.xml????е????????Struts2????????????
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Struts2_1000_FileUpload</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>