• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internal functionality of getServletContext()

 
NitishK Kumar
Ranch Hand
Posts: 40
Chrome Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I want to know what happens when we write:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64992
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It returns the container's implementation of the ServletContext interface.
 
NitishK Kumar
Ranch Hand
Posts: 40
Chrome Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tejas Shah
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic