Pass value: Web. XML passes the parameter to get the value in the Web. XML in the servlet

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.