Chapter 6: Advanced Tomcat Features Note the use
Chapter 6: Advanced Tomcat Features Note the use of a lock around this lookup code. This ensures serialized access to the JNDI lookup code. There is production evidence on very highly loaded systems that the code may not be totally thread-safe. (Thanks to Anne Horton for this valuable information.) At this point, myConncontains an instance of a database connection, which can be used to access the MySQL database immediately. Configuring Mail Sessions JavaMail is a standard programming API used by Java developers to create and send e-mail. Tomcat 6 supports JavaMail by providing the JNDI configuration of a JavaMail session as a resource, using its own factory code to create a JavaMail session for the Web application. This enables any Web applications running under Tomcat to use JNDI to look up and use the session. The example in the following section shows how to send e-mail from within a JSP using a JavaMail session configured as a JNDI resource. The JSP will post a form to a collaborating servlet. The servlet will use the configured JavaMail session to send the actual e-mail. It takes advantage of the examplesWeb application that is distributed with Tomcat 6. Adding a Resource Definition to the Application Context Descriptor The first step is to configure a mail session as a JNDI resource. In the Context descriptor of the examples Web application (the $CATALINA_HOME/webapps/examples/META-INF/context.xmlfile), add the following resource definition inside the
For high quality website hosting services please check cheap web hosting website.