Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why Servlet interface doesn't have getServletContext()?

 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why javax.servlet.Servlet interface doesn't have getServletContext() method?

Why this question came in my mind because:
1] It has getServletConfig() method.
2] javax.servlet.GenericServlet class has getServletContext() method.

Thanks.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet can access the ServletConfig, the ServletConfig provides access to the ServletContext. It's all to do with the intent of each interface. The Servlet interface Defines methods that all servlets must implement, the The ServletConfig interface (is) used by a servlet container to pass information to a servlet during initialization.

If you check the API description for GenericServlet it states:
This method is supplied for convenience. It gets the context from the servlet's ServletConfig object.
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David for good explanation.
[ November 30, 2005: Message edited by: rathi ji ]
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, context is something optional, right? Can be or not.
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by dema rogatkin:
So, context is something optional, right? Can be or not.


Please describe the question?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not optional, but it is not the responsibility of the Servlet to return the ServletContext, instead it is the ServletConfig's responsibility (via the container) to define the servlet context, and the config is made availabel to the Servlet.

When you extend GenericServlet, it provides a getServletContext method, but it is just a convenient short cut provided by the class and not related to the behaviour defined by the interfaces.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic