黑马程序员
ServletContext–概述
ServletContext–获取
@WebServlet("/ServletContext_Demo1")
public class ServletContext_Demo1 extends HttpServlet {
protected void doPost(HttpServletRequest request
, HttpServletResponse response
) throws ServletException
, IOException
{
ServletContext servletContext
= request
.getServletContext();
ServletContext servletContext1
= this.getServletContext();
System
.out
.println(servletContext
==servletContext1
);
}
protected void doGet(HttpServletRequest request
, HttpServletResponse response
) throws ServletException
, IOException
{
doPost(request
, response
);
}
}
ServletContext–功能–获取MIME
String mimeType
= servletContext
.getMimeType("a.jpg");
System
.out
.println(mimeType
);