servlet specification 2.3, chapter10:Application event listeners are classes that implement one or more of the servlet event listener interfaces<Servlet Constext Events>
listener interace: javax.servlet.SerletContextListenerAn Example of listener User:
When the application starts up, the listener class is notified.The application logs on to the database, and stores the connection in the servlet context.
<omited>

解决方案 »

  1.   

    in web.xml
    <servlet>
    <…………>
    <load-on-startup>1</load-on-startup>
    </servlet>
      

  2.   

    在web.xml中
      <servlet-mapping>
        <servlet-name>CartServlet</servlet-name>  //Servlet类名
        <url-pattern>/cart.jsp</url-pattern>  //将cart.jsp映射到Servet
      </servlet-mapping>
    在IE输入.../cart.jsp实际执行的是CartServlet
      

  3.   

    关注eyeieye(魔之眼) 的方法
      

  4.   

    感谢eyeieye(魔之眼)和bdsc() ,不过两位提供的都是在application startup时加载的方法,那么tomcat中的application是在tomcat启动时启动呢,还是在第一个用户访问时启动?
      

  5.   

    一般在你的应用文件夹下会建立一个web-inf文件夹,里面放一些不想让用户的道的数据,比如又一个classes文件夹,来放servlet或者bean等等。
    在web-inf下你可以建立一个web.xml文件,它的格式你可以参考%tomcat%/conf/web.xml来写,可以制定自己应用中用到的servlet。其中有一个<load-on-startup>1</load-on-startup>的标签,来定义servlet的启动时间,1为Tomcat启动时候启动。如果没有在这个文件里声明的得servlet会在第一个用户访问时候启动。但是推荐把所有servlet都在此文件中声明,可以实现servlet的别名访问,只是不写<load-on-startup>1</load-on-startup>,那么它就会在第一个用户访问时在启动了。
    good luck...
      

  6.   

    The servlet context has just been created and is avaible to service its first request.other methods, except what i said, is container-specific.Good luck!
      

  7.   

    web.xml 例子片断:
    ...
    <servlet>
       <servlet-name>controller</servlet-name>
          <description>
            This servlet plays the "controller" role in the MVC architecture
            used in this application.  It is generally mapped to the ".do"
            filename extension with a <servlet-mapping> element, and all form
            submits in the app will be submitted to a request URI like
            "saveCustomer.do", which will therefore be mapped to this servlet.        The initialization parameter namess for this servlet are the
            "servlet path" that will be received by this servlet (after the
            filename extension is removed).  The corresponding value is the
            name of the action class that will be used to process this request.
          </description>
          <servlet-class>com.mycompany.mypackage.ControllerServlet</servlet-class>
          <init-param>
            <param-name>listOrders</paramName>
            <param-value>com.mycompany.myactions.ListOrdersAction</param-value>
          </init-param>
          <init-param>
            <param-name>saveCustomer</paramName>
            <param-value>com.mycompany.myactions.SaveCustomerAction</param-value>
          </init-param>
          <!-- Load this servlet at server startup time -->
          <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
          <servlet-name>controller</servlet-name>
          <url-pattern>*.do</url-pattern>
        </servlet-mapping>