• 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

Relation between ServletConfig and ServletContext

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers

On page 163 HFSJ, it says -

getServletConfig().getServletContext().getInitParameter()

is same as -

this.getServletContext().getInitParameter()

Which object does 'this' refers to here? If it is ServletConfig object then how come our service()/doXXX() method has an implicit reference to ServletConfig object?

Please explain.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"this" is refered to servlet,servlet have both getServletConfig() and getServletContext(),first one return a ServletConfig,second one return a ServletContext,ServletConfig has a method named getServletContext,which return a ServletContext,and ServletContext has a method named getInitParamter() retrive init parameter.
am i clear?
 
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We know that GenericServlet is extending Servlet and ServletConfig interfaces.

In javax.servlet.Servlet interface contains getServletConfig()

and

javax.servlet.ServletConfig contains getServletContext()

1.* So the first one is getServletConfig(). that is one called from GenericServlet and further we can get ServletContext on called getServletContext() on object of ServletConfig as it is having one and that is implemented in GenericServlet

2.** In second case, this is used to get ServletContext as the method is declared in ServletConfig and defined in GenericServlet.


Hope it is clear to you.

Pawan
SCJP 5.0, SCWCD 1.4
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic