取得服务的相关信息
System.out.println(this.getServletContext().getServerInfo());
获得web应用的根目录
System.out.println(this.getServletContext().getContextPath());
获取web应用的参数(配置数据库)
<context-param>
<param-name>name</param-name>
<param-value>haoren</param-value>
</context-param>
String sex = this.getServletContext().getInitParameter("sex");
System.out.print(sex);
数据共享
ServeltDemo1:
this.getServletContext().setAttribute("address", "chengdu");
ServeltDemo2:
String address = (String) this.getServletContext().getAttribute("address");