user2088260
user2088260

Reputation:

Java : ServletContext not avaliable in Eclipse (IDE FOR EE)

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

enter image description here

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

Answers (2)

user2030471
user2030471

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

sanbhat
sanbhat

Reputation: 17622

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

Upvotes: 1

Related Questions