1. Concept: representative of the web application, the container may program (server) to communicate
2. Get:
1. Get the request object
ServletContext context1 = request.getServletContext();
2. Get through HttpServlet
ServletContext context2 = this.getServletContext();
3. Function:
1. Obtain the MIME type
MIME types: a definition file in Internet communication process data type
- Format: Large type / small type text / html image / jpeg
- Gets:
String getMimeType (String File);
For example:
//通过HttpServlet获取
ServletContext context = this.getServletContext();
//定义文件名称
String filename="a.jpg";
//获取 MIME 类型
String mimetype=context.getMimeType(filename);//image/jpeg
System.out.println(mimetype);
2. domain objects: data sharing
1.setAttribute(String name,Object value)
2.getAttribute(String name)
3.removeAttribute(String name)
ServletContext 对象范围:所有用户所有请求的数据
3. Get real files (server) path
method:
String getRealPath(String path)
Reproduced in: https: //www.jianshu.com/p/197b52c9e8c0