tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amos Shapira <amos.shap...@webcollage.com>
Subject RE: Running a servlet on startup
Date Tue, 11 Jul 2000 17:10:41 GMT
Yoav,

The server.xml file is a tomcat-specific config file.  I was talking
about a WEB-INF/web.xml file which should reside under the
web-application's directory.  The DTD for this file is defined in the
Servlet 2.2 spec.  There is the place to put the <load-on-startup>

For a quick kickstart, here is one of my web.xml files:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application
2.2//EN' 'http://java.sun.com/j2ee/dtds/web-app_2_2.dtd'>
<web-app>

  <display-name>
    Sample web.xml file
  </display-name>

  <context-param>
    <param-name>
      CatalogPath
    </param-name>
    <param-value>
      ../../Java/com/elseweb/catalog/partnershipmodelTest/Data
    </param-value>
  </context-param>

  <context-param>
    <param-name>
      ProviderId
    </param-name>
    <param-value>
      Google
    </param-value>
  </context-param>

  <context-param>
    <param-name>
      PartnerCenterBundleName
    </param-name>
    <param-value>
      PartnerCenterMessages.properties
    </param-value>
  </context-param>

  <context-param>
    <param-name>
      ProviderCenterBundleName
    </param-name>
    <param-value>
      ProviderCenterMessages.properties
    </param-value>
  </context-param>

  <session-config>
    <!-- the default Tomcat web.xml file sets session timeout to 30 seconds
-->
    <session-timeout>
      2147483647
    </session-timeout>
  </session-config>

  <servlet>
    <servlet-name>
      Login
    </servlet-name>

    <jsp-file>
      /login.jsp
    </jsp-file>

    <load-on-startup>
      1
    </load-on-startup>
  </servlet>

  <!-- from here onward this is standard stuff -->
  <mime-mapping>
    <extension>jpg</extension>
    <mime-type>image/jpeg</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>txt</extension>
    <mime-type>text/plain</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>jpeg</extension>
    <mime-type>image/jpeg</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>gif</extension>
    <mime-type>image/gif</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>htm</extension>
    <mime-type>text/html</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
  </mime-mapping>
</web-app>

> -----Original Message-----
> From: ymorahg@gist.com [mailto:ymorahg@gist.com]
> Sent: Tuesday, July 11, 2000 7:59 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: Running a servlet on startup
> 
> 
> Amos,
> 
> Thanks for answering my question. How do I go about adding the
> load-on-startup to the context of the Web application? My 
> context looks like
> this:
> 
> <Context path="/gist" docBase="webapps/gist" debug="0" 
> reloadable="true">
> 
> do I just add load-on-startup="myservlet" to the above line? 
> I have a simple
> test servlet which just outputs some text to the terminal. If the
> load-on-startup works, when will I see this text printed -- 
> when the first
> servlet on my Web application is served?
> 
> Thanks for your help,
> -Yoav
> 
> ---------------------------
> Yoav Morahg
> Software Engineer
> Gist Communications
> (212) 965-1999 xt 122
> ymorahg@gist.com
> 
> 
> -----Original Message-----
> From: Amos Shapira [mailto:amos.shapira@webcollage.com]
> Sent: Tuesday, July 11, 2000 12:29 PM
> To: 'tomcat-user@jakarta.apache.org'
> Subject: RE: Running a servlet on startup
> 
> 
> Hi,
> 
> I think what you have to do is to define a web application 
> which includes
> this servlet and assign a <load-on-startup> tag for that 
> servlet in the
> context of the web application.  Be aware that this way (which is
> supported by the standard of Java Servlets 2.2) may cause your
> servlet's init() method to be invoked every time the servlet is loaded
> (i.e. if the engine removed the servlet earlier for some reason or
> if the servlet is configured under more than one name, or declared
> as "single thread model" which will cause multiple instances of it
> to be created).
> 
> As for the class name question, I think you should give the
> plain "full" class name, in your case it would be "myservlet" since
> it looks it is in the default Java package (no "package" clause in its
> .java file, right?)
> 
> Hope this helps,
> 
> --Amos Shapira
> WebCollage
> 
> 
> > -----Original Message-----
> > From: ymorahg@gist.com [mailto:ymorahg@gist.com]
> > Sent: Tuesday, July 11, 2000 7:26 PM
> > To: tomcat-user@jakarta.apache.org
> > Subject: Running a servlet on startup
> >
> >
> > Hi.
> >
> > I want to run a startup servlet to set some global system
> > properties when
> > Tomcat starts up. I think I need to add a <ContextInterceptor
> > class-"myservlet" /> to my server.xml file. Is this correct?
> >
> > Also, if this is correct, if my servlet resides in
> > webapps/myservlets/WEB-INF/classes/myservlet.class what do I
> > put for the
> > value inside the class="????" I see the example is
> > org.apache.tomcat.context.servletname, so what does mine map to?
> >
> > Thanks a lot for your help!
> >
> > -Yoav
> >
> > ---------------------------
> > Yoav Morahg
> > Software Engineer
> > Gist Communications
> > (212) 965-1999 xt 122
> > ymorahg@gist.com
> >
> >
> 

Mime
View raw message