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 element. If this file and directory do not exist, add them explicitly:
mail.smtp.host localhost
This will configure the JNDI mail/Session Context, referring to an SMTP server running on localhost. If you are connecting to a remote SMTP server, change the value of localhost to the name or IP address of your server. You can also modify the port used (if it is not at the standard port 25) by setting the mail .smtp.portparameter. Adding a Reference to a Mail Session Resource in the Deployment Descriptor In the deployment descriptor (the $CATALINA_HOME/webapps/jsp-examples/WEB-INF/web.xmlfile), you must declare a reference to the JNDI resource. Add the following lines after the declarations, but before the descriptions in the web.xmlfile:

For high quality website hosting services please check cheap web hosting website.

Comments are closed.