package struts.uploadAndDownload.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.opensymphony.xwork2.ActionSupport;
public class UploadAction extends ActionSupport {
private static final long serialVersionUID = -2212925161785463886L;
private File file;
private String fileContentType;
private String fileFileName;
private String clientPath;
//
public String execute() throws Exception{
System.out.println();
System.out.println("单个文件上传:");
System.out.println("文件名:"+fileFileName);
System.out.println("file 's type:"+this.getFileContentType());
System.out.println("clientPath="+clientPath);
String pathRoot = "E:\\tjx\\eclipsewp\\Struts2Demo2\\WebContent";
File fileTemp = new File(pathRoot+"\\upload");
if(!fileTemp.exists())fileTemp.mkdir();
File fileSave = new File(pathRoot+"\\upload\\"+fileFileName);
System.out.println("save path==="+fileSave);
boolean b = writer(file, fileSave);
System.out.println("保存结果:"+b);
return SUCCESS;
}
private boolean writer(File file,File fileSave){
try {
FileInputStream reader = new FileInputStream(file);
FileOutputStream writer = new FileOutputStream(fileSave);
byte[] bts = new byte[2048];
int len ;
while((len=reader.read(bts)) !=-1){
writer.write(bts,0,len);
}
reader.close();
writer.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public void setFilename(File filename) {
this.file = filename;
}
public File getFilename() {
return file;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileFileName() {
return fileFileName;
}
public String getClientPath() {
return clientPath;
}
public void setClientPath(String clientPath) {
this.clientPath = clientPath;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
struts2上传(eclipse web项目)
共28个文件
jar:7个
xml:4个
jsp:3个
5星 · 超过95%的资源 需积分: 10 33 下载量 145 浏览量
2012-09-12
17:09:38
上传
评论
收藏 3.18MB ZIP 举报
温馨提示
eclipse web项目,上传文件。测试时,建议自己建立那个用于存放上传文件的文件夹 (UploadAction中指定的路径是E:\tjx\eclipsewp\Struts2Demo2\WebContent\upload,你可以自定义,到时改一下action中写的那个路径\\) struts2版本:struts2.3.4
资源推荐
资源详情
资源评论
收起资源包目录
Struts2Demo2文件上传.zip (28个子文件)
Struts2Demo2
WebContent
upload
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 592B
classes
struts.xml 675B
struts
uploadAndDownload
action
DownloadAction.class 1KB
UploadAction.class 3KB
lib
freemarker-2.3.15.jar 859KB
commons-logging-1.0.4.jar 37KB
ognl-2.7.3.jar 234KB
xwork-core-2.1.6.jar 1.49MB
commons-fileupload-1.2.1.jar 56KB
struts2-core-2.1.8.1.jar 738KB
commons-io-1.3.2.jar 86KB
uploadAndDownload
downloadList.jsp 920B
upload.jsp 792B
js
upload
upload.js 999B
prototype.js 121KB
index.jsp 686B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 305B
org.eclipse.wst.common.component 466B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 503B
org.eclipse.jdt.core.prefs 395B
src
struts.xml 675B
struts
uploadAndDownload
action
DownloadAction.java 815B
UploadAction.java 2KB
.project 1KB
.classpath 601B
build
共 28 条
- 1
资源评论
- Rico_c2015-11-15包包很不错哦 下载了
- lingxinlingyi2014-04-22可以使用 很标准的架构
- 一直在敏捷的路上2014-06-13确实可以使用,但还是不够详细
- autumnwln2014-12-03的确可以用,很标准的框架。学习了
wakata
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功