发现2种方法获取servletContext,一种是以request来获取,另一种是直接调用继承父类的方法
public class Demo2Servlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletContext servletContext1 = request.getServletContext();
ServletContext servletContext2 = this.getServletContext();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}