• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why Servlet interface doesn't have getServletContext()?

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David for good explanation.
[ November 30, 2005: Message edited by: rathi ji ]
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, context is something optional, right? Can be or not.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic