Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ethnos; import com.opensymphony.xwork2.ActionSupport; import java.io.File; import javax.servlet.http.HttpServletRequest; import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext; /** * * @author bpit */ public class SENNUploadAction extends ActionSupport { private File t1; private String t1FileName; private String t1ContentType; public String execute() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); String destPath = "..\\Upload"; try { File destFile = new File(destPath, t1FileName); FileUtils.copyFile(getT1(), destFile); } catch (Exception e) { request.setAttribute("err", "Sorry, file can't be uploaded at this moment!!!"); return "error"; } request.setAttribute("msg", "File uploaded successfully!!!"); return "success"; } /**+++++++++++++++++++++ * @return the t1 */ public File getT1() { return t1; } /** * @param t1 the t1 to set */ public void setT1(File t1) { this.t1 = t1; } /** * @return the t1FileName */ public String getT1FileName() { return t1FileName; } /** * @param t1FileName the t1FileName to set */ public void setT1FileName(String t1FileName) { this.t1FileName = t1FileName; } /** * @return the t1ContentType */ public String getT1ContentType() { return t1ContentType; } /** * @param t1ContentType the t1ContentType to set */ public void setT1ContentType(String t1ContentType) { this.t1ContentType = t1ContentType; } }