this blog is original: Integrated still Silicon Valley (http://www.atguigu.com) System tutorial (deep thank) and network of existing resources (blogs, documents, books, etc.), the source of resources I will markThe purpose of this blog: ① summary of their own learning process, equivalent to study notes ② to share their own experience to everyone, learn from each other, communication, not commercialcontent inevitably appear problems, welcome to correct, exchange, discussion, you can leave a message, can also be contacted by the following ways. I Internet technology enthusiasts, Internet technology enthusiastsWeibo: Ivan is in 0221qq:951226918
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -----------------------------
1. About ServletConfig
1) In some cases the servlet may need to access the servlet container or access external resources with a servlet container, so the Serlvet engine needs to pass the object that represents the Servlet container to the servlet. In addition, information such as the friendly name and initialization parameters set for a servlet in the Web. xml file also needs to be passed to the servlet;
2) The servlet engine encapsulates both the object (ServletContext) of the servlet container and the configuration parameter information of the servlet into an object called ServletConfig and is passed to the Servlet instance object when it is initialized. The ServletConfig interface is used to define the methods that the ServletConfig object needs to provide externally so that these methods can be called in the servlet program to obtain information;
3) The servlet engine invokes the init (ServletConfig config) method of the Servlet's instance object to pass the ServletConfig object to the servlet;
4) The Servlet.getservletconfig () method must return a reference to the ServletConfig object passed in by the Init (ServletConfig config) method.
2.ServletConfig Method:getinitparameternames (), Getinitparameter (), Getservletname (), Getservletcontext ()
1) Configure the Servlet initialization parameters
1 <!--Configure the servlet and map servlet and the node must be in front of the Load-on-starup node -2 <servlet>3 <!--the name of the Servlet's registry -4 <Servlet-name>HelloServlet</Servlet-name>5 <!--the full class name of the Servlet -6 <Servlet-class>Com.jason.javaweb.helloServlet</Servlet-class>7 8 9 <!--Configuring initialization parameters for a servlet -Ten <Init-param> One <!--Name of parameter - A <Param-name>User</Param-name> - <!--parameter Values - - <Param-value>Root</Param-value> the </Init-param> - - <Init-param> - <Param-name>Password</Param-name> + <Param-value>Zhangzhen</Param-value> - </Init-param> + A <!--You can specify the time when the servlet was created - at <Load-on-startup>1</Load-on-startup> - - </servlet>
2) Get initialization parameters:
①getinitparameter (String name): Gets the initialization parameter for the specified parameter name
②getinitparameternames (): Gets the enumeration object consisting of parameters
③getservletname (): Gets the servlet configuration name
1 @Override2 Public voidInit (ServletConfig servletconfig)throwsservletexception {3System.out.println ("Init");4 5 //gets a specified initialization parameter6String user = Servletconfig.getinitparameter ("User");7 System.out.println (user);8 //gets the enumeration of the initial change parameter9enumeration<string> names =Servletconfig.getinitparameternames (); Ten while(Names.hasmoreelements ()) { OneString name =names.nextelement (); AString value =Servletconfig.getinitparameter (name); -System.out.println ("Name:" + name + "Value:" +value); - } the}
[ServletConfig objects in the original]java Web learning Note 05:servlet