Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two ways to get a ServletContext

 
nagalatha mitta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
HFSJ book says two ways to get a servletcontext-
1st way-getServletCongig().getServletContext().getInitParameter()
2nd way-this.getServletContext().getInitParameter()
if anybody knows "this" stands for what in the 2nd way please let me know

thanks in advance
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's for HttpServlet.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, "this" refers to an instance of the class in which the code is executing

In your case, it is the servlet instance
 
James Mark
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
these are the methods inherited from the GenericServlet which is being available to your Servlet class through inheritance.When different requests came for your Servlet its doXXX() excecuted as diffrent Threads.

So simply the currently running Object will be your Servlet ofcourse.
Rest is simple use of the this operator on the currently running Servlet insatnce and making use of the inherited methods.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James said:
these are the methods inherited from the GenericServlet which is being available to your Servlet class through inheritance


Adding to what james said,
The GenericServlet implements ServletConfig which contains the getServletContext method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic