Tapestry上传多附件 [转]

以发送5个附件为实例:

private IUploadFile file0;

public IUploadFile getFile0() {
return file0;
}

public void setFile0(IUploadFile value) {
file0 = value;
}

protected void initialize() {
file0 = null;
}
private IUploadFile file1;

public IUploadFile getFile1() {
return file1;
}

public void setFile1(IUploadFile value) {
file1 = value;
}
private IUploadFile file2;

public IUploadFile getFile2() {
return file2;
}

public void setFile2(IUploadFile value) {
file2 = value;
}
private IUploadFile file3;

public IUploadFile getFile3() {
return file3;
}

public void setFile3(IUploadFile value) {
file3 = value;
}
private IUploadFile file4;

public IUploadFile getFile4() {
return file4;
}

public void setFile4(IUploadFile value) {
file4 = value;
}

-------------------------------------------------

List affixList = new ArrayList();
System.out.println("file= "+ this.getFile0());
if (this.getFile0()!= null) {
affixList.add(this.getFile0());
}
if (this.getFile1() != null) {
affixList.add(this.getFile1());
}
if (this.getFile2()!= null) {
affixList.add(this.getFile2());
}
if (this.getFile3()!= null) {
affixList.add(this.getFile3());
}
if (this.getFile4()!= null) {
affixList.add(this.getFile4());
}

-------------------------------------------------

List affixPathList = MailUtil.saveTempFile(visit.getUserid(),affixList);

/**
* 将上传的附件保存在临时文件夹
* @param dirName String
* @param affixList List
* @throws Exception
* @return List
*/
public static List saveTempFile(String

以发送5个附件为实例:

private IUploadFile file0;

public IUploadFile getFile0() {
return file0;
}

public void setFile0(IUploadFile value) {
file0 = value;
}

protected void initialize() {
file0 = null;
}
private IUploadFile file1;

public IUploadFile getFile1() {
return file1;
}

public void setFile1(IUploadFile value) {
file1 = value;
}
private IUploadFile file2;

public IUploadFile getFile2() {
return file2;
}

public void setFile2(IUploadFile value) {
file2 = value;
}
private IUploadFile file3;

public IUploadFile getFile3() {
return file3;
}

public void setFile3(IUploadFile value) {
file3 = value;
}
private IUploadFile file4;

public IUploadFile getFile4() {
return file4;
}

public void setFile4(IUploadFile value) {
file4 = value;
}

-------------------------------------------------

List affixList = new ArrayList();
System.out.println("file= "+ this.getFile0());
if (this.getFile0()!= null) {
affixList.add(this.getFile0());
}
if (this.getFile1() != null) {
affixList.add(this.getFile1());
}
if (this.getFile2()!= null) {
affixList.add(this.getFile2());
}
if (this.getFile3()!= null) {
affixList.add(this.getFile3());
}
if (this.getFile4()!= null) {
affixList.add(this.getFile4());
}

-------------------------------------------------

List affixPathList = MailUtil.saveTempFile(visit.getUserid(),affixList);

/**
* 将上传的附件保存在临时文件夹
* @param dirName String
* @param affixList List
* @throws Exception
* @return List
*/
public static List saveTempFile(String dirName, List affixList)
throws Exception {
List filePathList = new ArrayList();
try {
String dirPath = makeMailDir(dirName + "//temp");

if (!affixList.isEmpty()) {
Iterator it = affixList.iterator();
while (it.hasNext()) {
IUploadFile uploadFile = (IUploadFile) it.next();
String fileName = uploadFile.getFileName();
File file = new File(dirPath + fileName);
uploadFile.write(file);
filePathList.add(dirPath + fileName);

}
logger.debug("已将附件写进服务器临时文件夹");
}

} catch (Exception ex) {
logger.error("in method saveTempFile", ex);
throw ex;
}
return filePathList;
}

-------------------------------------------------

mail.setAffixList(affixPathList);

dirName, List affixList)
throws Exception {
List filePathList = new ArrayList();
try {
String dirPath = makeMailDir(dirName + "//temp");

if (!affixList.isEmpty()) {
Iterator it = affixList.iterator();
while (it.hasNext()) {
IUploadFile uploadFile = (IUploadFile) it.next();
String fileName = uploadFile.getFileName();
File file = new File(dirPath + fileName);
uploadFile.write(file);
filePathList.add(dirPath + fileName);

}
logger.debug("已将附件写进服务器临时文件夹");
}

} catch (Exception ex) {
logger.error("in method saveTempFile", ex);
throw ex;
}
return filePathList;
}

-------------------------------------------------

mail.setAffixList(affixPathList);

你可能感兴趣的:(tapestry)