//获取Servletcontext对象
//第一种方式:
ServletContext sc=this.getServletContext();
//第二种方式:
ServletContext sc2=this.getServletConfig().getServletContext();
//第三种方式:
ServletContext sc3=request.getSession().getServletContext();
System.out.println(scsc2);
System.out.println(scsc3);
//数据存储
sc.setAttribute(“str”,“ServletContext对象学习”);
//数据获取
sc.getAttribute(“str”);
//返回Object类型:
//不同的用户可以给ServletContext对象进行数据的存取。
//获取的数据不存在返回null。
String str=sc.getInitParameter(“name”);
//根据键的名字返回web.xml中配置全局数据的值,返回String类型;
//如果数据不存在返回null
//将静态数据和代码进行解耦
System.out.println(“全局配置参数”+str);
String path=sc.getRealPath("/doc/1.text");
System.out.println(path);