(1)生命周期
ServletContext中的属性的生命周期从创建开始,到服务器关闭而
(2).获取ServletContext
1、request获取servletContext
ServletContext servletContext = request.getServletContext();
2、使用ContextLoader
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
3、使用spring注入自动注入
@Autowired
private ServletContext servletContext;
(3).使用ServletContext存取
1、添加属性:setAttribute(String name,Object ob);
2、得到值: getAttribute(String); //返回Object
3、删除属性:removeAttribute(String name);