标签:value names next pattern === his let class lang
<servlet>
<servlet-name>configServlet</servlet-name>
<servlet-class>cn.lzm.servlet.ServletConfigServlet</servlet-class>
<init-param>
<param-name>like</param-name>
<param-value>pear</param-value>
</init-param>
<init-param>
<param-name>color</param-name>
<param-value>blue</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>configServlet</servlet-name>
<url-pattern>/config</url-pattern>
</servlet-mapping>
//获取ServletConfig对象
ServletConfig config = this.getServletConfig();
//获取当前ServletName
String servletName = config.getServletName();
System.out.println(servletName); //configServlet
//读取初始化配置
//获取键
Enumeration<String> keys = config.getInitParameterNames();
while (keys.hasMoreElements()){
String key = keys.nextElement();
System.out.print(key+"===>"); //color===>blue like===>pear
//根据键获取值
System.out.println(config.getInitParameter(key));
标签:value names next pattern === his let class lang
原文地址:https://www.cnblogs.com/xiaominaaaa/p/14386312.html