This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Internal functionality of getServletContext() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Internal functionality of getServletContext()" Watch "Internal functionality of getServletContext()" New topic
Author

Internal functionality of getServletContext()

NitishK Kumar
Ranch Hand

Joined: Oct 20, 2010
Posts: 40

Hi I want to know what happens when we write:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

It returns the container's implementation of the ServletContext interface.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
NitishK Kumar
Ranch Hand

Joined: Oct 20, 2010
Posts: 40

Bear Bibeault wrote:It returns the container's implementation of the ServletContext interface.


I mean to ask that generally a method is invoked on an object and getServletContext() is in servletconfig interface. So, how container locates the servletconfig object.

For eg:
We write as follows



Similarly, here also it should be as . So how the container locates the servletconfig object?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41178
    
  45
Similarly, here also it should be as "servletconfig.getServletContext()"...

It actually is. "getServletContext()" is a short form of "this.getServletContext()", where "this" refers to the current object. In your example, the class extends from GenericServlet, which implements ServletConfig and has a getServletContext method.


Ping & DNS - my free Android networking tools app
Tejas Shah
Greenhorn

Joined: Oct 26, 2009
Posts: 23

Adding some information..

And then the call passes to the container and container which takes care of the servlet context, is returned. The actual implementations may be found in container's code.


-Tejas
Cherish your life...!!
 
Consider Paul's rocket mass heater.
 
subject: Internal functionality of getServletContext()
 
Similar Threads
setting attribute for the entire application
Confusion in code
j2eecertificate mock exam question
"application" and "getServeltContext"
to access the name of server