Struts2文件上传相关支持
package rj.uploadify;import java.io.File;import org.apache.struts2.ServletActionContext;import rj.tools.SystemTool;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class UploadifyAction extends ActionSupport {//上传文件private File file;//上传文件的文件名,XXXXFileName(XXXX要同上传文件的引用名一致 Struts2拦截器会自动注入)。private String fileFileName;//上传文件的MIMe类型,XXXXFileName(XXXX要同上传文件的引用名一致 Struts2拦截器会自动注入)。private String fileContentType;//上传文件的描述信息private String descripition;//接收上传文件是带的参数private String textStr;//保存上传文件的目录,相对于web应用的根路径,在Sring的配置文件中注入 注入值,"common/uploadFiles/sites";private String uploadDir;public String upload()throws Exception{System.out.println(textStr);//在控制台显示上传所带参数// 文件保存路径String path = ServletActionContext.getServletContext().getRealPath(uploadDir);System.out.println(path);//保存文件,并返回,图片保存在服务器上的全限定名,如:/文件保存路径/文件名?????String url = SystemTool.uploadFile(file, fileFileName, path);System.out.println(url);return null;}//getter setterpublic File getFile() {return file;}public void setFile(File file) {this.file = file;}public String getFileFileName() {return fileFileName;}public void setFileFileName(String fileFileName) {this.fileFileName = fileFileName;}public String getUploadDir() {return uploadDir;}public void setUploadDir(String uploadDir) {this.uploadDir = uploadDir;}public String getFileContentType() {return fileContentType;}public void setFileContentType(String fileContentType) {this.fileContentType = fileContentType;}public String getDescripition() {return descripition;}public void setDescripition(String descripition) {this.descripition = descripition;}public String getTextStr() {return textStr;}public void setTextStr(String textStr) {this.textStr = textStr;}}