Hi, neal,

I am going to do my best to state this without being offensive, which I 
don't intend to be.  You really need to look at what I am saying, however 
you take this, neal.

The problem you are having is why I asked the questions which, 
unfortunately, you took as insults.  I thought you were missing this 
information and was trying to find out if that was true.  You need to look 
at the web.xml for struts, and the dtd for web.xmls generally.  If you look 
at the struts example, you will find something like the following in web.xml:

<web-app>
..........

   <!-- Example Database Initialization Servlet Configuration
   <servlet>
     <servlet-name>database</servlet-name>
     <servlet-class>org.apache.struts.example.DatabaseServlet</servlet-class>
     <init-param>
       <param-name>debug</param-name>
       <param-value>2</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
   -->


   <!-- Standard Action Servlet Configuration (with debugging) -->
   <servlet>
     <servlet-name>action</servlet-name>
     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
     <init-param>
       <param-name>application</param-name>
       <param-value>com.tresbeau.i18n.messages</param-value>
     </init-param>
     <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/xml/struts-config.xml</param-value>
     </init-param>
     <init-param>
       <param-name>debug</param-name>
       <param-value>2</param-value>
     </init-param>
     <init-param>
       <param-name>detail</param-name>
       <param-value>2</param-value>
     </init-param>
     <init-param>
       <param-name>validate</param-name>
       <param-value>true</param-value>
     </init-param>
     <load-on-startup>2</load-on-startup>
   </servlet>


   <!-- Standard Action Servlet Mapping -->
   <servlet-mapping>
     <servlet-name>action</servlet-name>
     <url-pattern>*.do</url-pattern>
   </servlet-mapping>


..........
</web-app>

Additionally, you will find that servlets themselves have an initialization 
method (init).  So, you need to delve more into servlets and more into the 
way the xml is used to configure things in the Model 2 architecture.

The core of the struts app, of course, is the ActionServlet.  With that in 
mind, consider the following class:

package com.oreilly.struts.storefront.framework;

import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import org.apache.struts.action.ActionServlet;
import com.oreilly.struts.storefront.service.IStorefrontService;
import com.oreilly.struts.storefront.service.StorefrontServiceImpl;
import com.oreilly.struts.storefront.framework.util.IConstants;
import com.oreilly.struts.storefront.framework.exceptions.DatastoreException;
/**
  * Extend the Struts ActionServlet to perform your own special
  * initialization.
  */
public class ExtendedActionServlet extends ActionServlet {

   public void init() throws ServletException {

     // Make sure to always call the super's init() first
     super.init();

     // Initialize the persistence service
     try{
       // Create an instance of the service interface
       StorefrontServiceImpl serviceImpl = new StorefrontServiceImpl();

       // Store the service into the application scope
       getServletContext().setAttribute( IConstants.SERVICE_INTERFACE_KEY,
                                         serviceImpl );
     }catch( DatastoreException ex ){
       // If there's a problem initializing the service, disable the web app
       ex.printStackTrace();
       throw new UnavailableException( ex.getMessage() );
     }
   }
}
This is from Chuck's upcoming (soon) book.  This ought to be enough to get 
you kick started.  I once again highly recommend that you read Jason 
Hunter's book on servlets.

micael


At 12:48 AM 9/7/2002 -0700, you wrote:
>In a previous thread someone mentioned that it is possible to set a servlet
>to run as Tomcat is started.
>
>Could someone please provide me with a syntactical example of how to set
>this up?
>
>I have searched the documentation, I've searched for exmaples in the web.xml
>files, and I've scoured the Internet and I can not find any documentation or
>examples.
>
>I guess I'm just looking int he wrong places???
>
>Thanks.
>Neal
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to