package com.wuhn.struts2.action;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
* @author wuhn
* @创建时间 2015-12-09
* @功能 上传
* **/
public class Struts2UploadAction extends ActionSupport {
private File image; //上传的文件
private String imageFileName; //文件名称 要注意前缀要和file的变量一样
private String imageContentType; //文件类型 要注意前缀要和file的变量一样
private String result;//返回信息
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFileName() {
return imageFileName;
}
public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
@Override
public String execute() throws Exception{
//设置存储路径
String path = ServletActionContext.getServletContext().getRealPath("/images");
File localFile = new File(path);
if(!localFile.exists()){
localFile.mkdir();
}
System.out.println("image:"+image);
System.out.println("imageFileName:"+imageFileName);
System.out.println("imageContentType:"+imageContentType);
System.out.println("文件是否存在:"+image.exists());
//保存文件
FileUtils.copyFile(image, new File(localFile, imageFileName));
result = "上传成功!";
return SUCCESS;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
文件上传下载【struts2】
共43个文件
jar:13个
xml:6个
jsp:5个
需积分: 3 11 下载量 67 浏览量
2016-02-27
13:42:16
上传
评论
收藏 4.73MB ZIP 举报
温馨提示
项目代码详细请看这里 http://blog.csdn.net/qw765811529/article/details/50750979
资源推荐
资源详情
资源评论
收起资源包目录
Struts2Upload.zip (43个子文件)
Struts2Upload
.project 2KB
.mymetadata 312B
src
log4j2.xml 482B
app_zh_CN.properties 527B
struts.xml 4KB
com
wuhn
struts2
action
Struts2UploadAction.java 2KB
BatchStruts2UploadAction.java 2KB
Struts2DownloadAction.java 2KB
WebRoot
WEB-INF
classes
log4j2.xml 482B
app_zh_CN.properties 527B
struts.xml 4KB
com
wuhn
struts2
action
Struts2DownloadAction.class 2KB
BatchStruts2UploadAction.class 3KB
Struts2UploadAction.class 3KB
lib
asm-commons-3.3.jar 37KB
commons-fileupload-1.3.1.jar 67KB
log4j-core-2.2.jar 807KB
commons-io-2.2.jar 170KB
freemarker-2.3.22.jar 1.24MB
commons-lang3-3.2.jar 376KB
xwork-core-2.3.24.1.jar 661KB
javassist-3.11.0.GA.jar 600KB
asm-tree-3.3.jar 21KB
log4j-api-2.2.jar 130KB
asm-3.3.jar 43KB
ognl-3.0.6.jar 223KB
struts2-core-2.3.24.1.jar 813KB
web.xml 739B
jsp
03.jsp 1KB
error.jsp 840B
02.jsp 861B
01.jsp 988B
index.jsp 966B
images
20151026165425.png 118KB
META-INF
MANIFEST.MF 36B
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 88B
org.eclipse.wst.common.component 477B
.jsdtscope 500B
.classpath 529B
共 43 条
- 1
资源评论
您宁
- 粉丝: 18
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- UE4仅k位移产生完美行走动作-UE4项目
- tensorflow-2.6.3-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.6.2-cp39-cp39-win-amd64.whl
- tensorflow-2.6.2-cp39-cp39-manylinux2010-x86-64.whl
- 基于Python卷积神经网络人脸识别驾驶员疲劳检测与预警系统源码+使用说明+全部资料.zip
- BPNN-预测.rar
- 灾难分类数据集 PNG(12类 4.8K+ 张图像)
- java8和17的windows、linux版本
- MDK5.18版本,退出仿真不会有问题
- 预测-AE-1.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功