单个Servlet的配置对象
web.xml
java
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>com.ambow.test.FirstServlet</servlet-class>
<init-param>
<param-name>charset</param-name>
<param-value>utf-8</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first01</url-pattern>
</servlet-mapping>
获取单个Servlet的初始化参数
java
ServletConfig config;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
this.config = config;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String charset = config.getInitParameter("charset");//获取初始化参数
...
}