The method getServletContext() is undefined for the type HttpServletRequest
ServletContext context = request.getServletContext();
getServletContext() is available from HttpServlet class that your servlet extended. You can invoke the method as if it were defined in your own servlet class
ServletContext context = getServletContext();