config内置对象

config内置对象
  request 是处理用户的请求的对象, response 是处理响应的对象, session 是代表一个用户的对象,主要用于实现登录等操作,
  config 内置对象主要是用来获取配置文件中的初始化参数, config 内置对象的类型是 "javax.servlet.ServletConfig".

Demo: 取得配置文件的初始化参数

 1 @SuppressWarnings("serial")
 2 public class EmpServlet extends HttpServlet {
 3     @Override
 4     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 5         this.config(req, resp);
 6     }
 7     public void config(HttpServletRequest req, HttpServletResponse resp) {
 8         //获取config 内置对象
 9         ServletConfig config = super.getServletConfig();
10         //获取初始化参数
11         String initName = config.getInitParameter("name");
12         System.out.println(initName);
13     }
14 }

 

posted @ 2019-04-22 11:03  笑长不爱笑QvQ  阅读(220)  评论(0编辑  收藏  举报