将多个 HTTP 参数从 servlet 传递到 EJB 的安全规范方法是什么?该应用程序是一个基于 Web 的 SMTP 客户端,它采用以下参数:
- 从
- 到
- 密件抄送
- 抄送
- 学科
- 身体
为了使模型( ) 与视图( ) 和控制器( EJB
) 分开,我想避免将 an直接传递给.JSP
servlet
HttpServletRequest
EJB
- 我应该使用
Session
变量吗? - 我应该传递 6 个参数吗?要传递这 6 个参数,我必须在控制层中执行业务逻辑。
代码:
public String send_message(HttpServletRequest request) {
try {
Properties properties = System.getProperties();
properties.put("mail.smtp.host", SMTP_HOST);
Session session = Session.getInstance(properties, null);
String from = request.getParameter("from");
String to = request.getParameter("to");
String cc = request.getParameter("cc");
String bcc = request.getParameter("bcc");
String subject = request.getParameter("subject");
String body = request.getParameter("body");
MimeMessage message = new MimeMessage(session);
Address sender = new InternetAddress(from);
message.setFrom(sender);
Address[] toAddresses = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.TO, toAddresses);
Address[] ccAddresses = InternetAddress.parse(cc);
message.setRecipients(Message.RecipientType.CC, ccAddresses);
Address[] bccAddresses = InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.BCC, bccAddresses);
message.setSubject(subject);
message.setText(body);
Transport.send(message);
return "Your message was sent successfully!";
} catch (AddressException AE){
return "Oops! There was an error parsing the addresses!";
} catch (SendFailedException SFE){
return "Oops! There was an error sending the message!";
} catch (MessagingException ME){
return "Oops! There was an error sending the message!";
}
}