在 html 页面有 <input type="file" name="certificate" onchange="displayFileValue(this);" class="huan2"/>
有个按纽能 动态生成 上面的代码,用来实现同时上传多个文件 action 内 接收代码:protected List<File> certificates;
protected List<String> certificateFileNames;
Get/Setpublic List<File> getCertificate() {
return certificates;
}public void setCertificate(List<File> certificates) {
this.certificates = certificates;
}public List<String> getCertificateFileName() {
return certificateFileNames;
}public void setCertificateFileName(List<String> certificateFileNames) {
this.certificateFileNames = certificateFileNames;
}
上面的代码,当我上传一个文件的时候没问题当上传多个文件时,就获取不到 文件` 在线等待` By 巧顾网
有个按纽能 动态生成 上面的代码,用来实现同时上传多个文件 action 内 接收代码:protected List<File> certificates;
protected List<String> certificateFileNames;
Get/Setpublic List<File> getCertificate() {
return certificates;
}public void setCertificate(List<File> certificates) {
this.certificates = certificates;
}public List<String> getCertificateFileName() {
return certificateFileNames;
}public void setCertificateFileName(List<String> certificateFileNames) {
this.certificateFileNames = certificateFileNames;
}
上面的代码,当我上传一个文件的时候没问题当上传多个文件时,就获取不到 文件` 在线等待` By 巧顾网
解决方案 »
- 100分在线等 hibernate 映射小问题。一个女生的请求
- 序列化的对象作为webserivces 调用一个方法的参数出错,可是不通过
- 刚学jsp,问下,打<%时,是不是有代码提示出现的(自动出现%>)
- tomcat启动问题求助
- 请问是否可以在同一个tomcat下的webapp目录下只更新其中的一个项目,另外的项目不会因为其它的更新而重启.
- 怎样实现按删除链接后,这条记录就消失??
- struts中的session变量的使用!
- 我在用javac编译JAVA文件时出现以下错误
- JDBC连接MS sql服务器的问题。
- jdk问题
- 小弟很想学JAVA但不知道该怎么去学。那位兄弟能指点一下、指出一条路线?
- 在Action中处理DAO方法中传值为List的应该怎么处理?
private String title;
private List<File> upload;
private List<String> uploadContentType;
private List<String> uploadFileName; // 接受依赖注入的属性
private String savePath; // 接受依赖注入的方法
public void setSavePath(String value) {
this.savePath = value;
} private String getSavePath() throws Exception {
return ServletActionContext.getRequest().getRealPath(savePath);
} public void setTitle(String title) {
this.title = title;
} public String getTitle() {
return (this.title);
} public List<File> getUpload() {
return upload;
} public void setUpload(List<File> upload) {
this.upload = upload;
} public List<String> getUploadContentType() {
return uploadContentType;
} public void setUploadContentType(List<String> uploadContentType) {
this.uploadContentType = uploadContentType;
} public List<String> getUploadFileName() {
return uploadFileName;
} public void setUploadFileName(List<String> uploadFileName) {
this.uploadFileName = uploadFileName;
} @Override
public String execute() throws Exception {
for (int i = 0; i < upload.size(); i++)
{
InputStream is = new FileInputStream(upload.get(i)); String root = ServletActionContext.getRequest().getRealPath(
"/upload"); File destFile = new File(root, this.getUploadFileName().get(i)); OutputStream os = new FileOutputStream(destFile); byte[] buffer = new byte[400]; int length = 0; while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
} is.close(); os.close();
Dao dao = new Dao();
dao.getMessage();
String[] filecount = dao.getL2().getItems();
int len = filecount.length;
int no;
if(len == 0)
{
no = 1;
}
else no = Integer.parseInt(filecount[len-1])+1;
dao.insert(no,this.getUploadFileName().get(i));
}
return "success";
}
public void validate()
{
if(upload == null || upload.size() <=0 )
{
this.addFieldError("upload", "上传文件不能为空!");
}
}
}