以发送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);
评论
lyo 2007-05-07
怎么可以把附件的数量些死呢?!
ralf_realman 2006-10-10
兄弟抬举了,这是别人的文章,我觉得比较好就拿来了,哈哈哈
eyejava 2006-09-28
兄台真是低调啊.这么好的文章躲在这个角落里面,可惜可惜,放到论坛上去吧
发表评论

您还没有登录,请登录后发表评论

ralf_realman
搜索本博客
博客分类
最近加入圈子
存档
最新评论
评论排行榜