servlet配置了初始化參數後,web容器在建立servlet實例對象時,會自動將這些初始化參數封裝到ServletConfig對象中,並在調用servlet的init方法時,將ServletConfig對象傳遞給servlethtml
<servlet>java
<servlet-name></servlet-name>web
<servlet-class></servlet-class>api
<init-param>this
<param-name></param-name>spa
<param-value></param-value>code
</init-param>htm
</servlet>對象
TIPS:blog
在實際開發中 直接能夠經過getServletConfig()獲得ServletConfig對象
String |
getInitParameter(String name) Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. |
Enumeration |
getInitParameterNames() Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. |
ServletContext |
getServletContext() Returns a reference to the ServletContext in which the caller is executing. |
String |
getServletName() Returns the name of this servlet instance. |