(1) Lode-on-startup, the servlet will be called at the start of the project (primarily called the Init method, for security sake, generally should not establish a URL mapping for the servlet), generally used as preprocessing some data, or with multithreading to establish timed tasks
<servlet><pre name= "code" class= "HTML" ><span style= "font-family:arial, Helvetica, Sans-serif;" > </span><span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:12PX;" > <servlet-name>FirstServlet</servlet-name></span>
<servlet-class>com.hunhun.FirstServlet</servlet-class> <!--1 represents the start order of multiple preprocessed servlets--< Lode-on-startup>1</lode-on-startup> </servlet>
(2) Init-param, can be used to do some configuration information of the servlet
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class> com.hunhun.firstservlet</servlet-class> <init-param> <param-name>encoding</ param-name> <param-value>utf-8</param-value> </init-param> </servlet>
You can use This.getservletconfig (). Getinitparameter ("encoding") in the do* method of Firstservlet; Get encoding value in Web. XML utf-8
More than 2.1 Init-param
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class> com.hunhun.firstservlet</servlet-class> <init-param> <param-name>encoding</ param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>author</param-name> <param-value>hunhun</param-value> </ init-param> <init-param> <param-name>versioon</param-name> <param-value >1.0</param-value> </init-param> </servlet>
Can be in the do* method of Firstservlet
enumeration<string> names = This.getservletconfig (). Getinitparameternames (); while (Names.hasmoreelements ()) { //name for each init-param name String name=names.nextelement (); }
(3) Context-param, global configuration information, can be used in multiple servlets
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class> com.hunhun.firstservlet</servlet-class> <init-param> <param-name>encoding</ param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>author</param-name> <param-value>hunhun</param-value> </ init-param> <init-param> <param-name>versioon</param-name> <param-value >1.0</param-value> </init-param> </servlet> <context-param> <param-name>date</param-name> <param-value>2011-12-3 10:30:24</param-value> </context-param>
You can use string date = This.getservletcontext () in the do* method of *servlet. Getinitparameter ("date"); Get to date
Servlet (v) Some of the common configuration of Web. xml