tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ch...@pg.ebx.com
Subject preloaded feture
Date Fri, 08 Dec 2000 07:51:37 GMT
Hi,

May I know that is't tomcat have the feture that preload a servlet each
time I start the tomcat? For example, every time I start the tomcat, it
will automatically load a servlet (this servlet will read a properties
file, and set these properties to to ServletContext). If so, how to
configure? Below is the sample servlet. Many thanks!!


import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletContext;
import javax.servlet.http.*;

public class ReadProperties extends HttpServlet
{
     String szDatabaseURL = "";
     String szDatabaseLogin = "";
     String szDatabasePassword =   "";
     String szSchema     = "";

     private static ResourceBundle resources;

     static
     {
          try
          {
          resources = ResourceBundle.getBundle("test", Locale.getDefault
());
         }
          catch (MissingResourceException mre)
          {
               System.err.println(mre + "\ntest.properties not found.");
          }
     }

     public void init(ServletConfig config) throws ServletException
     {
          super.init(config);

          System.out.println("Start the service");
          try
          {
               szDatabaseURL = resources.getString("dburl");
               szDatabaseLogin = resources.getString("user");
               szDatabasePassword = resources.getString("password");
               szSchema = resources.getString("schema");

               ServletContext servContext = getServletContext();
               servContext.setAttribute("DB_URL", szDatabaseURL);
               servContext.setAttribute("DB_USER", szDatabaseLogin);
               servContext.setAttribute("DB_PASSWORD", szDatabasePassword);
               servContext.setAttribute("DB_SCHEMA", szSchema);
          }
          catch (Exception e)
          {
               System.out.println("Properties Error: " + e.getMessage());
          }
     }

     public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
     {
     }

     public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
     {
     }
}



Chian Hwa Kok
Software Engineer
e-Business Sdn. Bhd.
Tel: (604) 890-8143   Ext: 143
Fax: (604) 890-1771
E-Mail: chkok@pg.ebx.com


Mime
View raw message