----- Original Message ----- From: "Justyna Horwat" To: "Tomcat Developers List" Sent: Sunday, September 08, 2002 3:26 PM Subject: [PATCH] jakarta-servlet-api: JSP 1.2 examples > This is a patch for the JSP 1.2 SendMail example. The implementation of > this example is missing. > > 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. As I recall, JavaMail is a "click-through" license, so it can't be bundled. > > This patch includes updates to the existing jsp files, adds the missing > implementation file, and updates the build.xml file. > > jakarta-servletapi-5/jsr152/build.xml > jakarta-servletapi-5/jsr152/examples/mail/sendmail.jsp > jakarta-servletapi-5/jsr152/examples/mail/sendmail.txt > jakarta-servletapi-5/jsr152/examples/WEB-INF/classes/SendMailServlet.java > <-- NEW > > Justy > ---------------------------------------------------------------------------- ---- > Index: jsr152/build.xml > =================================================================== > RCS file: /home/cvs/jakarta-servletapi-5/jsr152/build.xml,v > retrieving revision 1.2 > diff -u -r1.2 build.xml > --- jsr152/build.xml 27 Aug 2002 13:17:42 -0000 1.2 > +++ jsr152/build.xml 8 Sep 2002 22:18:27 -0000 > @@ -19,6 +19,7 @@ > > > > + > > > Index: jsr152/examples/mail/sendmail.jsp > =================================================================== > RCS file: /home/cvs/jakarta-servletapi-5/jsr152/examples/mail/sendmail.jsp,v > retrieving revision 1.1.1.1 > diff -u -r1.1.1.1 sendmail.jsp > --- jsr152/examples/mail/sendmail.jsp 27 Aug 2002 13:16:51 -0000 1.1.1.1 > +++ jsr152/examples/mail/sendmail.jsp 8 Sep 2002 22:19:15 -0000 > @@ -16,10 +16,13 @@ > SMTP service for your network. >
  • The application logic assumes that no user authentication is required > by your SMTP server before accepting mail messages to be sent.
  • > +
  • You will need to have the > + JavaMail Implementation classes available to your container > + in order for this example to work.
  • >
  • All of the fields below are required.
  • > > > -
    > + > > > > > Index: jsr152/examples/mail/sendmail.txt > =================================================================== > RCS file: /home/cvs/jakarta-servletapi-5/jsr152/examples/mail/sendmail.txt,v > retrieving revision 1.1.1.1 > diff -u -r1.1.1.1 sendmail.txt > --- jsr152/examples/mail/sendmail.txt 27 Aug 2002 13:16:51 -0000 1.1.1.1 > +++ jsr152/examples/mail/sendmail.txt 8 Sep 2002 22:19:33 -0000 > @@ -16,10 +16,13 @@ > SMTP service for your network. >
  • The application logic assumes that no user authentication is required > by your SMTP server before accepting mail messages to be sent.
  • > +
  • You will need to have the > + JavaMail Implementation classes available to your container > + in order for this example to work.
  • >
  • All of the fields below are required.
  • > > > - > + >
    > > > ---------------------------------------------------------------------------- ---- > /* $Id$ > * > */ > > 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$ $Date$ > */ > > 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(""); > writer.println(""); > writer.println("Example Mail Sending Results"); > writer.println(""); > writer.println(""); > > 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("Message successfully sent!"); > > } catch (Throwable t) { > > writer.println(""); > writer.println("ENCOUNTERED EXCEPTION: " + t); > writer.println("
    ");
    >             t.printStackTrace(writer);
    >             writer.println("
    "); > writer.println("
    "); > > } > > // Prepare the ending of our response > writer.println("

    "); > writer.println("Create a new message
    "); > writer.println("Back to examples home
    "); > writer.println(""); > writer.println(""); > > } > > } > > ---------------------------------------------------------------------------- ---- > -- > To unsubscribe, e-mail: > For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: