1、jspsmart文件上傳(普通表單,帶有普通表單域、若干個文件選擇域)
頁面:
!-- 隱藏文件域 begin
div class="control-group" id="hiddenFileDiv" style="display: none;">
label class="control-label" for="file">File/label>
div class="controls">
input type="file" name="file1" id="file1" />
span class="help-inline">/span>
/div>
/div>-->
!-- 隱藏文件域 end
div class="control-group">
label class="control-label" for="file">crossmatch/label>
div class="controls">
select name="crossmatch" id="crossmatch">
option value="Y">Y/option>
option value="N">N/option>
/select>
span class="help-inline">/span>
/div>
/div>-->
div class="control-group">
div class="controls">
!-- a href="javascript:void(0);" id="upload" class="btn">submit/a>-->
button type="submit" class="btn" id="upload">submit/button>
button type="reset" class="btn" id="reset">reset/button>
/div>
/div>
/form>
Session session = Session.getDefaultInstance(props, auth);
// 設(shè)置session,和郵件服務(wù)器進(jìn)行通訊
MimeMessage message = new MimeMessage(session);
// 設(shè)置郵件發(fā)送者的地址
message.setFrom(new InternetAddress(username));
// 設(shè)置郵件接收的地址
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
// 設(shè)置郵件主題
message.setSubject(mailSubject);
// 構(gòu)造Multipart
Multipart mp = new MimeMultipart();
// 向Multipart添加正文
MimeBodyPart content = new MimeBodyPart();
content.setContent(msg, "text/html;charset=gb2312");
mp.addBodyPart(content);
// 向Multipart添加附件
Enumeration efile = vfile.elements();
while(efile.hasMoreElements()){
MimeBodyPart fattach = new MimeBodyPart();
String fName = efile.nextElement().toString();
FileDataSource fds = new FileDataSource(fName);
fattach.setDataHandler(new DataHandler(fds));
fattach.setFileName(MimeUtility.encodeWord(fds.getName(), "GB2312",null));
mp.addBodyPart(fattach);
}
vfile.removeAllElements();
message.setContent(mp);
// 設(shè)置郵件發(fā)送時期
message.setSentDate(new Date());
message.saveChanges();
//發(fā)送郵件
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
標(biāo)簽:南充 肇慶 吳忠 梅州 白銀 臨沂 昌都 黔東
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《jspsmart文件上傳與郵件發(fā)送的實例》,本文關(guān)鍵詞 jspsmart,文件,上傳,與,郵件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。