Reputation:
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
Upvotes: 3
Views: 9177
Reputation:
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();
Upvotes: 6
Reputation: 17622
getServletContext()
method is not defined for HttpServletRequest
, you need to get it from HttpSession
OR
by simply calling getServletContext()
within your Servlet
Upvotes: 1