一个web应用中的所有Servlet共享同一个ServletContext对象,通过该对象进行数据共享
ServletContext对象通常被称为域对象
this.getServletContext().setAttribute(String namne, Object object);//设置name属性的值
this.getServletContext().getAttribute(String name);//取出name属性的值
this.getServletContext().getInitParameter(String name);//获取web.xml中标签对<context-param>中配置的name参数的值
this.getServletContext().getInitParameterNames();//获取web.xml中标签对<context-param>中配置的所有参数名称
this.getServletContext().getRequestDispatcher("1.jsp").forward(httpServletRequest, httpServletResponse);//内部请求转发
this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");//将资源以流形式返回, 返回InputStream
this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");//返回资源的绝对路径