package action;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class UploadAction extends ActionSupport{
private File file;
private String fileFileName;
private String fileContentType;
public 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 getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
public void upload() {
HttpServletRequest req=ServletActionContext.getRequest();
String savePath=req.getParameter("savePath");
String path = ServletActionContext.getServletContext().getRealPath("/");
System.out.println(fileContentType);
System.out.println(fileFileName);
try {
FileUtils.copyFile(file, new File(path +savePath+ fileFileName));
String outPath = ServletActionContext.getRequest().getScheme()
+ "://" + ServletActionContext.getRequest().getServerName()
+ ":" + ServletActionContext.getRequest().getServerPort()
+ ServletActionContext.getRequest().getContextPath() + "/";
ServletActionContext.getResponse().getWriter()
.print(outPath + savePath +fileFileName);
} catch (IOException e) {
e.printStackTrace();
}
}
}
最近下载更多
微信网友_6549826556514304 LV2
2023年7月6日
darkknight LV1
2022年5月23日
微信网友_5906437341401088 LV1
2022年4月7日
zz臧震1234 LV1
2022年3月10日
1qaz2wsxxzl LV1
2021年12月3日
420256987 LV1
2021年11月4日
000星望000 LV1
2021年11月1日
ln_lz LV13
2021年8月26日
yuyanxinyu LV1
2021年8月20日
jenyfang LV2
2021年6月16日
最近浏览更多
微信网友_6549826556514304 LV2
2023年7月6日
haoyi198 LV3
2023年1月11日
fy0088 LV2
2022年9月25日
ttttt111
2022年6月24日
暂无贡献等级
darkknight LV1
2022年5月23日
微信网友_5906437341401088 LV1
2022年4月7日
zz臧震1234 LV1
2022年3月10日
1qaz2wsxxzl LV1
2021年12月3日
420256987 LV1
2021年11月4日
000星望000 LV1
2021年11月1日

