Example 9-1. The org.apache.struts.action.PlugIn interface public interface PlugIn
Example 9-1. The org.apache.struts.action.PlugIn interface public interface PlugIn { /** * Notification that the specified application module isbeing started. */ public void init(ActionServlet servlet, ApplicationConfig config) throws ServletException; /** * Notification that the application module is being shutdown. */ public void destroy( ); } During startup of a Struts application, the ActionServlet calls the init( ) method for each PlugIn that is configured; the framework supports configuration of one or more PlugIns for each application. Initialization routines that your plug-in needs to perform should be done during the init( )method. This is a good time to initialize a database connection or establish a connection to a remote system, for example.[1] [1] You also can initialize a database connection through the use of a datasource. The second method that your plug-in must implement is the destroy( )method. The framework calls this method when the application is being shut down. You should perform any necessary cleanup during this time. For example, this is the perfect time to close database connections, remote sockets, or any other resources that the plug-in is using. Let’s provide a concrete example of how to use the Struts framework’s PlugIn mechanism. Suppose that your application needs the ability to communicate with an EJB tier. One of the first things you must do before that can occur is to get a reference to the Java Naming and Directory Interface (JNDI) service. JNDI enables clients to access various naming and directory services, such as datasources, JavaMail sessions, and EJB home factories. Example 9-2 illustrates a simple example of acquiring an InitialContext for a JNDI service using the Struts PlugIn mechanism. Example 9-2. An example of using the Struts PlugIn mechanism package com.oreilly.struts.storefront.framework.ejb; import java.util.Hashtable; import javax.naming.InitialContext; import javax.naming.Context; import org.apache.struts.action.ActionServlet; import org.apache.struts.config.ApplicationConfig; import org.apache.struts.action.PlugIn; import javax.servlet.ServletException; public class JNDIConnectorPlugin implements PlugIn {
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.