建站极客
网络编程 JSP编程 正文
邮件发送简单例子-jsp文件
所属分类:
网络编程 / JSP编程
阅读数:
1862
收藏 0
赞 0
分享
MailExample.jsp <html> <head> <title>JSP JavaMail Example </title> </head> <body> <%@ page import="java.util.*" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.internet.*" %> <%@ page import="javax.activation.*" %> <% String host = "yourmailhost"; String to = request.getParameter("to"); String from = request.getParameter("from"); String subject = request.getParameter("subject"); String messageText = request.getParameter("body"); boolean sessionDebug = false; // Create some properties and get the default Session. Properties props = System.getProperties(); props.put("mail.host", host); props.put("mail.transport.protocol", "smtp"); Session mailSession = Session.getDefaultInstance(props, null); // Set debug on the Session so we can see what is going on // Passing false will not echo debug info, and passing true // will. mailSession.setDebug(sessionDebug); // Instantiate a new MimeMessage and fill it with the // required information. Message msg = new MimeMessage(mailSession); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(to)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setText(messageText); // Hand the message to the default transport service // for delivery. Transport.send(msg); out.println("Mail was sent to " + to); out.println(" from " + from); out.println(" using host " + host + "."); %> </table> </body> </html>
Java Web实现的基本MVC实例分析 这篇文章主要介绍了Java Web实现的基本MVC,以完整实例形式较为详细的分析了JSP实现MVC架构的具体步骤与相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
jsp中调用java代码小结 大多数情况下, jsp 文档的大部分由静态文本(html)构成, 为处理该页面而创建的 servlet 只是将它们原封不动的传递给客户端
评论 0
收藏 0
赞 0
分享
struts2中一个表单中提交多个请求的例子(多个提交按钮) 在很多Web应用中,为了完成不同的工作,一个HTML form标签中可能有两个或多个submit按钮,Struts2中提供了另外一种方法,使得无需要配置可以在同一个action类中执行不同的方法(默认执行的是execute方法)
评论 0
收藏 0
赞 0
分享
servlet中session简介和使用例子 在servlet中,session是封装在javax.servlet.http.HttpSession这个接口中的,这个接口是构建在cookie或者URL重写的基础上,要得到一个HttpSession的实例,就可以通过HttpServletRequest的getSession()
评论 0
收藏 0
赞 0
分享
查看更多