ServlerContext_功能_获取MIME类型、ServlerContext_功能_域对象
ServlerContext_功能_获取MIME类型
获取MIME类型:
MIME类型:在互联通信过程中定义一种文件数据类型
格式:大类型/小类型 text/html image/jpeg
获取:String getMimeType(String file)
@WebServlet( value = "/ServletContext2")
public class ServletContext2 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取MIME类型
ServletContext context = this.getServletContext();
// 定义文件名称
String filename = "a.jpg";
// 获取MIME类型
String mimeType = context.getMimeType(filename);
System.out.println(mimeType);
}
}
ServlerContext_功能_域对象
域对象:setAttribute(String name,Object value)
getAttribute(String name)
removeAttribute(String name)
ServlerContext对象范围:所有用户所有请求数据