1 Transfer value: Web. XML Pass Parameter2 3 Configuring multiple Init-param in a servlet in Web. XML4 <servlet>5 ...6 <Init-param>7 <Param-name>Name</Param-name>8 <Param-value>Guan yu</Param-value>9 </Init-param>Ten <Init-param> One <Param-name>Age</Param-name> A <Param-value>20</Param-value> - </Init-param> - <Init-param> the <Param-name>Sex</Param-name> - <Param-value>Man</Param-value> - </Init-param> - </servlet> + - In the init () method of the servlet: + String name=this.getservletconfig (). Getinitparameter ("name"); A String age=this.getservletconfig (). Getinitparameter ("Age"); at - - servletconfig sc=this.getservletconfig ();
//Enumeration gets all configuration parameter information - enumeration E=sc.getservletconfig (). Getinitparameternames (); - While (E.hasmoreelements ()) { - Syso (Sc.getinitparameter (E.nextelement (). toString ())); in } - to + ----------------------------------- - Configuring multiple Context-param under Web-app in Web. XML the <Context-param> * <Param-name></Param-name> $ <Param-value></Param-value>Panax Notoginseng </Context-param> - the <Context-param> + <Param-name></Param-name> A <Param-value></Param-value> the </Context-param> + - $ Context: General refers to contextual environment $ - ServletContext: Refers to the context of the entire Web project, which represents the entire XML - the This.getservletcontext (). Getinitparameter ("Age"); - //Can be partially obtained by the whole (child to parent)Wuyi this.getservletconfig (). Getservletcontext (). Getinitparameter ("Age"); the - Servletconfig,servletcontext can get these two objects directly from this (Servlet)
Wu servletconfig scf=this.getservletconfig (); - ServletContext sct=this.getservletcontext (); About $ Init ( ), init (servletconfig config): in Genericservlet, init (servletconfig config) is called init (), so the overlay is init (), Instead of init (servletconfig config)
Pass value: Web. XML passes the parameter to get the value in the Web. XML in the servlet