1.读取servlet名称
2.读取web.xml中配置信息
<servlet>
<servlet-name>configServlet</servlet-name>
<servlet-class>com.ConfigServlet</servlet-class>
<init-param>
<param-name>username</param-name>
<param-value>root</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>root</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>configServlet</servlet-name>
<url-pattern>/config</url-pattern>
</servlet-mapping>
ServletConfig servletConfig = getServletConfig();
String username = servletConfig.getInitParameter("username");
String password = servletConfig.getInitParameter("password");
3.获取ServletContext对象。