config内置对象
request是处理用户的请求的对象,response是处理响应的对象,session是代表一个用户的对象,主要用于实现登录等操作
config内置对象主要是用来获取配置文件中的初始化参数
config内置对象的类型是javax.servlet.ServletConfig
取得配置文件的初始化参数
1.在web.xml文件中定义初始化参数
<!-- 在容器中配置出 路径对应的servlet -->
<servlet>
<servlet-name>empServlet</servlet-name>
<servlet-class>com.xie.EmpServlet</servlet-class>
<!-- 表示服务器一旦启动就初始化该servlet -->
<init-param>
<param-name>name</param-name>
<param-value>smith</param-value>
</init-param>
</servlet>
package com.xie;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class EmpServlet extends HttpServlet{
public void config(HttpServletRequest req, HttpServletResponse resp) {
//取得config内置对象
//ServletConfig config = this.getServletConfig();
//取得config内置对象
ServletConfig config = super.getServletConfig();
//取得初始化参数
String initName = config.getInitParameter("name");
System.out.println(initName);
}
}