You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ki...@apache.org on 2002/09/09 20:01:21 UTC
cvs commit: jakarta-servletapi-5/jsr152/examples/mail sendmail.jsp sendmail.txt
kinman 2002/09/09 11:01:20
Modified: jsr152 build.xml
jsr152/examples/mail sendmail.jsp sendmail.txt
Added: jsr152/examples/WEB-INF/classes SendMailServlet.java
jsr152/examples/WEB-INF/tags displayProducts.tag
helloWorld.tag panel.tag
Log:
- Patch by Justyna Horwat and Mark Roth.
Note by Jstyna:
The implementation has a dependency on the JavaMail classes. By default
the container does not have the JavaMail implementation classes ar
runtime so this example won't work "out of the box" until that jar file
is bundled.
Revision Changes Path
1.3 +1 -0 jakarta-servletapi-5/jsr152/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-servletapi-5/jsr152/build.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.xml 27 Aug 2002 13:17:42 -0000 1.2
+++ build.xml 9 Sep 2002 18:01:20 -0000 1.3
@@ -19,6 +19,7 @@
<path id="examples.classpath">
<pathelement location="${jsp-api.build}/classes"/>
<pathelement location="${servlet-api.jar}"/>
+ <pathelement location="${mail.jar}"/>
</path>
1.1 jakarta-servletapi-5/jsr152/examples/WEB-INF/classes/SendMailServlet.java
Index: SendMailServlet.java
===================================================================
/* $Id: SendMailServlet.java,v 1.1 2002/09/09 18:01:20 kinman Exp $
*
*/
import java.io.IOException;
import java.io.PrintWriter;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Example servlet sending mail message via JNDI resource.
*
* @author Craig McClanahan
* @version $Revision: 1.1 $ $Date: 2002/09/09 18:01:20 $
*/
public class SendMailServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
// Acquire request parameters we need
String from = request.getParameter("mailfrom");
String to = request.getParameter("mailto");
String subject = request.getParameter("mailsubject");
String content = request.getParameter("mailcontent");
if ((from == null) || (to == null) ||
(subject == null) || (content == null)) {
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/jsp/mail/sendmail.jsp");
rd.forward(request, response);
return;
}
// Prepare the beginning of our response
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Example Mail Sending Results</title>");
writer.println("</head>");
writer.println("<body bgcolor=\"white\">");
try {
// Acquire our JavaMail session object
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");
// Prepare our mail message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress dests[] = new InternetAddress[]
{ new InternetAddress(to) };
message.setRecipients(Message.RecipientType.TO, dests);
message.setSubject(subject);
message.setContent(content, "text/plain");
// Send our mail message
Transport.send(message);
// Report success
writer.println("<strong>Message successfully sent!</strong>");
} catch (Throwable t) {
writer.println("<font color=\"red\">");
writer.println("ENCOUNTERED EXCEPTION: " + t);
writer.println("<pre>");
t.printStackTrace(writer);
writer.println("</pre>");
writer.println("</font>");
}
// Prepare the ending of our response
writer.println("<br><br>");
writer.println("<a href=\"/mail/sendmail.jsp\">Create a new message</a><br>");
writer.println("<a href=\"/index.html\">Back to examples home</a><br>");
writer.println("</body>");
writer.println("</html>");
}
}
1.1 jakarta-servletapi-5/jsr152/examples/WEB-INF/tags/displayProducts.tag
Index: displayProducts.tag
===================================================================
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
<%@ attribute name="normalPrice" fragment="true" %>
<%@ variable fragment="normalPrice" name-given="name" %>
<%@ variable fragment="normalPrice" name-given="price" %>
<%@ attribute name="onSale" fragment="true" %>
<%@ variable fragment="onSale" name-given="name" %>
<%@ variable fragment="onSale" name-given="origPrice" %>
<%@ variable fragment="onSale" name-given="salePrice" %>
<table border="1">
<tr>
<td>
<jsp:invoke fragment="normalPrice">
<jsp:param name="name" value="Hand-held Color PDA"/>
<jsp:param name="price" value="$298.86"/>
</jsp:invoke>
</td>
<td>
<jsp:invoke fragment="onSale">
<jsp:param name="name" value="4-Pack 150 Watt Light Bulbs"/>
<jsp:param name="origPrice" value="$2.98"/>
<jsp:param name="salePrice" value="$2.32"/>
</jsp:invoke>
</td>
<td>
<jsp:invoke fragment="normalPrice">
<jsp:param name="name" value="Digital Cellular Phone"/>
<jsp:param name="price" value="$68.74"/>
</jsp:invoke>
</td>
<td>
<jsp:invoke fragment="normalPrice">
<jsp:param name="name" value="Baby Grand Piano"/>
<jsp:param name="price" value="$10,800.00"/>
</jsp:invoke>
</td>
<td>
<jsp:invoke fragment="onSale">
<jsp:param name="name" value="Luxury Car w/ Leather Seats"/>
<jsp:param name="origPrice" value="$23,980.00"/>
<jsp:param name="salePrice" value="$21,070.00"/>
</jsp:invoke>
</td>
</tr>
</table>
1.1 jakarta-servletapi-5/jsr152/examples/WEB-INF/tags/helloWorld.tag
Index: helloWorld.tag
===================================================================
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
Hello, world!
1.1 jakarta-servletapi-5/jsr152/examples/WEB-INF/tags/panel.tag
Index: panel.tag
===================================================================
<%--
- Copyright (c) 2002 The Apache Software Foundation. All rights
- reserved.
--%>
<%@ attribute name="color" %>
<%@ attribute name="bgcolor" %>
<%@ attribute name="title" %>
<table border="1" bgcolor="${color}">
<tr>
<td><b>${title}</b></td>
</tr>
<tr>
<td bgcolor="${bgcolor}">
<jsp:doBody/>
</td>
</tr>
</table>
1.2 +4 -1 jakarta-servletapi-5/jsr152/examples/mail/sendmail.jsp
Index: sendmail.jsp
===================================================================
RCS file: /home/cvs/jakarta-servletapi-5/jsr152/examples/mail/sendmail.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sendmail.jsp 27 Aug 2002 13:16:51 -0000 1.1
+++ sendmail.jsp 9 Sep 2002 18:01:20 -0000 1.2
@@ -16,10 +16,13 @@
SMTP service for your network.</li>
<li>The application logic assumes that no user authentication is required
by your SMTP server before accepting mail messages to be sent.</li>
+<li>You will need to have the <a href="http://java.sun.com/products/javamail">
+ JavaMail Implementation</a> classes available to your container
+ in order for this example to work.</li>
<li>All of the fields below are required.</li>
</ul>
-<form method="POST" action="../../SendMailServlet">
+<form method="POST" action="../SendMailServlet">
<table>
<tr>
1.2 +4 -1 jakarta-servletapi-5/jsr152/examples/mail/sendmail.txt
Index: sendmail.txt
===================================================================
RCS file: /home/cvs/jakarta-servletapi-5/jsr152/examples/mail/sendmail.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sendmail.txt 27 Aug 2002 13:16:51 -0000 1.1
+++ sendmail.txt 9 Sep 2002 18:01:20 -0000 1.2
@@ -16,10 +16,13 @@
SMTP service for your network.</li>
<li>The application logic assumes that no user authentication is required
by your SMTP server before accepting mail messages to be sent.</li>
+<li>You will need to have the <a href="http://java.sun.com/products/javamail">
+ JavaMail Implementation</a> classes available to your container
+ in order for this example to work.</li>
<li>All of the fields below are required.</li>
</ul>
-<form method="POST" action="../../SendMailServlet">
+<form method="POST" action="../SendMailServlet">
<table>
<tr>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>