I am trying to use ServletContext in my Servlet project as follows
ServletContext context =request.getServletContext();
problem is that when i try to use it i dont find getServletContext(); for request object .
what i get is see in attachement

i am new to Servlets and just got it from video tutorial series , please guide me how do i get ServletContext(); for my applocation
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();
getServletContext() method is not defined for HttpServletRequest, you need to get it from HttpSession
OR
by simply calling getServletContext() within your Servlet
Please see this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With