In the Java Servlet API, the only way to get the ServletContext
is through an instance of HttpSession
(Javadoc).
What if I don't want to create a session and only need the servlet context? In other words, why is there no getServletContext()
method in the HttpServletRequest
class?
EDIT
I know I can get the ServletContext
from the servlet itself, since it receives it during its initialization. However, I cannot get it from a HttpServletRequest
alone, even though it's linked to a servlet. So what if I have a request, but no reference to any servlet?