javamail发送邮件中碰到的几个问题
1.不定数附件的实现
<SCRIPT language='javascript'>
var fileNum = 0;
function addFile()
{
fileNum ++ ;
var nextNum = fileNum + 1;
var fileStr = "<table width=100% border=0 id=files"+fileNum+"><tbody><tr><td><input type=file id=filePath"+ fileNum +" name=filePath"+ fileNum +" style='width:100% '></td></tr></tbody></table>";
fileStr += "<table width=100% border=0 id=files"+nextNum+"><tbody><tr><td></td></tr></tbody></table>"
document.all("files"+fileNum).outerHTML = fileStr;
}
</SCRIPT>
.
<TR>
<TD align="right">
</TD>
<TD>
<table width="100%" border="0" id="files0">
<tr>
<td>
<INPUT type="file" id="filePath0" name="filePath0" style="width:100% " value="">
</td>
</tr>
</table>
<table width="100%" border="0" id="files1">
<tr>
<td>
</td>
</tr>
</table>
</TD>
</TR>
<TR>
<TD align="right">
</TD>
<TD>
<INPUT type="button" value="添加附件" onclick="addFile();">
</TD>
</TR>
.
var fileNum = 0;
function addFile()
{
fileNum ++ ;
var nextNum = fileNum + 1;
var fileStr = "<table width=100% border=0 id=files"+fileNum+"><tbody><tr><td><input type=file id=filePath"+ fileNum +" name=filePath"+ fileNum +" style='width:100% '></td></tr></tbody></table>";
fileStr += "<table width=100% border=0 id=files"+nextNum+"><tbody><tr><td></td></tr></tbody></table>"
document.all("files"+fileNum).outerHTML = fileStr;
}
</SCRIPT>
.
<TR>
<TD align="right">
</TD>
<TD>
<table width="100%" border="0" id="files0">
<tr>
<td>
<INPUT type="file" id="filePath0" name="filePath0" style="width:100% " value="">
</td>
</tr>
</table>
<table width="100%" border="0" id="files1">
<tr>
<td>
</td>
</tr>
</table>
</TD>
</TR>
<TR>
<TD align="right">
</TD>
<TD>
<INPUT type="button" value="添加附件" onclick="addFile();">
</TD>
</TR>
.
在点击"添加附件"的时候,就是在id为(file+数字)的中数字最大的table替换成2个table,数字再增加,依次类推
2.file控件和其他控件共用的问题
DiskFileUpload fu = new DiskFileUpload();
//设置上传文件的最大值
fu.setSizeMax(1024 * 1024 * 1024 * 30);
//设置缓存的值
fu.setSizeThreshold(4096);
fu.setRepositoryPath(System.getProperty("java.io.tmpdir"));
fu.setHeaderEncoding("UTF-8");
List fileItem = null;
Iterator it = null;
try {
fileItem = fu.parseRequest(httpServletRequest);
it = fileItem.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
}
//设置上传文件的最大值
fu.setSizeMax(1024 * 1024 * 1024 * 30);
//设置缓存的值
fu.setSizeThreshold(4096);
fu.setRepositoryPath(System.getProperty("java.io.tmpdir"));
fu.setHeaderEncoding("UTF-8");
List fileItem = null;
Iterator it = null;
try {
fileItem = fu.parseRequest(httpServletRequest);
it = fileItem.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
}
3.附件中文名称乱码问题
bp.setFileName(MimeUtility.encodeWord(fileds.getName(),"UTF-8",null)); 注意这个"encodeWord"是静态方法,不用实例化调用该方法