(1) Lode-on-startup, this servlet when the project is started it will be called (from the main phone init method, for security reasons, the servlet should not generally establish a URL mapping). Some data is often used as a pre-processing or use multithreading to build recurring 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>
Ability to 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 used in the do* method of Firstservlet
enumeration<string> names = This.getservletconfig (). Getinitparameternames (); while (Names.hasmoreelements ()) { //name is a String name=names.nextelement () for each init-param name; }
(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>
The ability to use string date = This.getservletcontext () in the do* method of *servlet. Getinitparameter ("date"); get the latest
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Servlets (children under five) Web. XML some common configurations