package com.xp.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
public class UploadAction {
/*
* 需要注意的是:
* 1、File file必须同jsp页面form中type=file中的name=”file“的值一致,比如下面的file
* 2、xxxFileName
* 3、xxxFileContentType
* 上面的xxx即为file,后两个属性是固定写法,格式必须为xxxFileName和xxxFileContentType
*
*/
private File file;
private String fileFileName;//文件名
private String fileFileContentType;//文件类型
public String upload() throws IOException {
HttpServletRequest request=ServletActionContext.getRequest();
String path=request.getRealPath("/upload");
InputStream is=new FileInputStream(file);//把要上传的文件放入IO流
OutputStream os=new FileOutputStream(new File(path,fileFileName));//设置上传路径,和新文件名(这里可以自定义命名规则,然后重命名的哦)
byte[] buffer=new byte[200];
int len=0;
while((len=is.read(buffer))!=-1){
os.write(buffer,0,len);//开始上传
}
os.close();
is.close();
return "success";
}
/**
* @return the file
*/
public File getFile() {
return file;
}
/**
* @param file the file to set
*/
public void setFile(File file) {
this.file = file;
}
/**
* @return the fileFileName
*/
public String getFileFileName() {
return fileFileName;
}
/**
* @param fileFileName the fileFileName to set
*/
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
/**
* @return the fileFileContentType
*/
public String getFileFileContentType() {
return fileFileContentType;
}
/**
* @param fileFileContentType the fileFileContentType to set
*/
public void setFileFileContentType(String fileFileContentType) {
this.fileFileContentType = fileFileContentType;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Struts2 单个、批量文件上传 精简源码
共31个文件
jar:12个
xml:3个
class:2个
需积分: 9 7 下载量 190 浏览量
2017-10-29
20:55:19
上传
评论
收藏 4.11MB RAR 举报
温馨提示
本案例是分为两种模式,单文件上传和多文件批量上传(可自动添加和减少上传文件的个数哦!) 欢迎交流吐槽。
资源推荐
资源详情
资源评论
收起资源包目录
Struts2 单个、批量文件上传 精简源码.rar (31个子文件)
12Struts2Upload
.project 1KB
.mymetadata 319B
src
struts.xml 2KB
com
xp
action
UploadAction.java 2KB
BatchUploadAction.java 2KB
struts.properties 123B
WebRoot
WEB-INF
classes
struts.xml 2KB
com
xp
action
BatchUploadAction.class 2KB
UploadAction.class 2KB
struts.properties 123B
lib
commons-lang3-3.1.jar 308KB
asm-commons-3.3.jar 37KB
struts2-core-2.3.4.jar 765KB
mysql-connector-java-5.1.20-bin.jar 784KB
javassist-3.11.0.GA.jar 600KB
freemarker-2.3.19.jar 909KB
commons-io-2.0.1.jar 156KB
asm-tree-3.3.jar 21KB
xwork-core-2.3.4.jar 614KB
commons-fileupload-1.2.2.jar 58KB
asm-3.3.jar 43KB
ognl-3.0.5.jar 222KB
web.xml 662B
upload
index.jsp 2KB
success.jsp 925B
js
jquery-1.11.3.js 278KB
META-INF
MANIFEST.MF 39B
.myeclipse
.settings
org.eclipse.jdt.core.prefs 330B
com.genuitec.eclipse.j2eedt.core.prefs 1KB
.classpath 1KB
批量上传.png 17KB
共 31 条
- 1
资源评论
血煞长虹
- 粉丝: 242
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功