aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Relation between ServletConfig and ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Relation between ServletConfig and ServletContext" Watch "Relation between ServletConfig and ServletContext" New topic
Author

Relation between ServletConfig and ServletContext

Mohit Jain
Ranch Hand

Joined: Jun 04, 2007
Posts: 74
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.


SCJP 5.0, SCWCD in progress
vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
"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?


SCJP 5.0<br />SCWCD1.4<br />SCBCD5
Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relation between ServletConfig and ServletContext