Servlet中 getServletConfig() 与 getServletContext() 的差异

Servlet中 getServletConfig() 与 getServletContext() 的区别
  • getServletContext() 是获取web.xml中 <context-param> 配置的参数

  • getServletConfig() 是获取web.xml 中 <servlet>中<init-param> 配置的参数

  • ServletConfig对象拥有对ServletContext对象的引用,所以可以通过
    getServletConfig().getServletContext()来获取ServletContext对象

  • ServletContext对象应用于整个web app,而ServletContext只应用于当前Servlet