日期:2014-05-20 浏览次数:20771 次
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="struts3.1" extends="struts-default"> <action name="upload" class="controller.Upload"> <result name="done">/zengjia.jsp</result> <result name="input">/register.jsp</result> </action> </package> <constant name="struts.ui.theme" value="simple"></constant> </struts>
package controller; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class Upload extends ActionSupport { private String username; private File uploadFile; private String uploadFileFileName; @Override public void validate() { } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public File getUploadFile() { return uploadFile; } public void setUploadFile(File uploadFile) { this.uploadFile = uploadFile; } public String getUploadFileFileName() { return uploadFileFileName; } public void setUploadFileFileName(String uploadFileFileName) { this.uploadFileFileName = uploadFileFileName; } public String execute() throws IOException { //用户名 System.out.println("username" + username); //放在哪 String targetDirectory = ServletActionContext.getRequest().getRealPath("/upload"); //生成对象 File target = new File(targetDirectory, uploadFileFileName); //复制对象 FileUtils.copyFile(uploadFile, target); return "done"; } }