Java之ServletContext篇

ServletContext对象

  代表整个web应用,可以和程序的容器(服务器) 通信

  通过request对象获取

    request.getServletContext();

  通过HttpServlet获取

    this.getServletContext();

  获取MIME类型:在互联网通信过程中定义的一种文件数据类型标准

    获取:String getMimeType(String file);

  域对象:共享数据

    setAttribute(String name,Object value);

    getAttribute(String name);

    removeAttribute(String name);

  ServletContext对象范围:所有用户所有请求的数据

  获取文件的真实(服务器)路径:

    String getRealPath(String path);

    

    

  

原文地址:https://www.cnblogs.com/zxh06820/p/12459901.html