struts上传多张图片怎么做,要求可以说上传中文的,而且图片可以重复上传不被覆盖
2个回答
展开全部
你指的是一次上传多张吗?我这有个自己写的例子:
//上传实体类
public class Upload {
private File photoes; //封装上传文件的属性
private String photoesFileName; //封装上传文件的名称属性
private String photoesContentType; //封装上传文件的类型属性
private String targetdir; //保存路径
private String targetfilename; //保存的文件名
public File getPhotoes() {
return photoes;
}
public void setPhotoes(File photoes) {
this.photoes = photoes;
}
public String getPhotoesFileName() {
return photoesFileName;
}
public void setPhotoesFileName(String photoesFileName) {
this.photoesFileName = photoesFileName;
}
public String getPhotoesContentType() {
return photoesContentType;
}
public void setPhotoesContentType(String photoesContentType) {
this.photoesContentType = photoesContentType;
}
public String getTargetdir() {
return targetdir;
}
public void setTargetdir(String targetdir) {
this.targetdir = targetdir;
}
public String getTargetfilename() {
return targetfilename;
}
public void setTargetfilename(String targetfilename) {
this.targetfilename = targetfilename;
}
}
这是上传图片的Action类中的部分代码
//获得服务器上保存上传文件的目录images的绝对路径
String realpath = ServletActionContext.getServletContext().getRealPath("/images");
//设置保存文件的目录
uld.setTargetdir(realpath);
//设置目标文件名
uld.setTargetfilename(generateFileName(uld.getPhotoesFileName()));
//把doc内容复制到target
FileUtils.copyFile(uld.getPhotoes(), new File(uld.getTargetdir(),uld.getTargetfilename()));
//上传实体类
public class Upload {
private File photoes; //封装上传文件的属性
private String photoesFileName; //封装上传文件的名称属性
private String photoesContentType; //封装上传文件的类型属性
private String targetdir; //保存路径
private String targetfilename; //保存的文件名
public File getPhotoes() {
return photoes;
}
public void setPhotoes(File photoes) {
this.photoes = photoes;
}
public String getPhotoesFileName() {
return photoesFileName;
}
public void setPhotoesFileName(String photoesFileName) {
this.photoesFileName = photoesFileName;
}
public String getPhotoesContentType() {
return photoesContentType;
}
public void setPhotoesContentType(String photoesContentType) {
this.photoesContentType = photoesContentType;
}
public String getTargetdir() {
return targetdir;
}
public void setTargetdir(String targetdir) {
this.targetdir = targetdir;
}
public String getTargetfilename() {
return targetfilename;
}
public void setTargetfilename(String targetfilename) {
this.targetfilename = targetfilename;
}
}
这是上传图片的Action类中的部分代码
//获得服务器上保存上传文件的目录images的绝对路径
String realpath = ServletActionContext.getServletContext().getRealPath("/images");
//设置保存文件的目录
uld.setTargetdir(realpath);
//设置目标文件名
uld.setTargetfilename(generateFileName(uld.getPhotoesFileName()));
//把doc内容复制到target
FileUtils.copyFile(uld.getPhotoes(), new File(uld.getTargetdir(),uld.getTargetfilename()));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询