ServletConfig objects
each servlet has a ServletConfig object
ServletConfig The object used to obtain the related configuration of the servlet.
get ServletConfig object: Direct This.getservletconfig () To return config object directly
the method that four config objects can call:
Getinitparameter (String name); Gets the value of the parameter initialization by initializing the name
Getinitparameternames (); By this method, returns an enumeration of String generics, enumeration<string>; Inside is the name of all the initialization. Gets all of the corresponding values through traversal.
With the enumeration object. Call the hasMoreElements () method to know if there is a next element. Nextelement (); get the next element
Getservletcontext (); Get ServletContext object
getservletname (); Get the name of the configuration
Configure initialization parameters
Configure the name of the initialization parameter in the label <init-param> configuration and the corresponding value <param-name> and <param-value>
5 ServletContext object to get Web project information
Overview of ServletContext objects
What is ServletContext
The context object for the Servletcontext:servlet. The ServletContext object is known to the content before and after the servlet. This object has only one Web project . Create a separate ServletContext object for each Web project when the server is started.
The role of ServletContext objects
Function one: To get Web project information
because a Web project has only one ServletContext object, This object is known to be relevant to the entire project.
Method:
gets the object of the ServletContext returned by the ServletContext object through the This.getservletcontext ();
gets the MIME type of the file: GetMimeType (filename);
gets the project name of the Web project request: Getcontextpath ();
To set the configuration of global initialization parameters: Add <context-param> tags to web.xml and add <param-name> and <param-value> values to this tab
gets the initialization parameter in the Web project XML file: Getinitparameter ("parameter name") returns the value of the parameter
gets the full name parameter name of the file for the Web project xml: Getinitparameternames (), returns an enumeration of string generics, enumeration<string>; inside is the name of all initialization. Gets all of the corresponding values through traversal.