一般在你的应用文件夹下会建立一个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...
An 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>
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>