This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Two ways to get a ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Two ways to get a ServletContext" Watch "Two ways to get a ServletContext" New topic
Author

Two ways to get a ServletContext

nagalatha mitta
Greenhorn

Joined: Jun 11, 2007
Posts: 26
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

Joined: Sep 11, 2006
Posts: 959

It's for HttpServlet.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
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

Joined: Jul 05, 2007
Posts: 115
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.


SCJP1.4(96%) SCWCD1.4(92%)
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
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.
 
 
subject: Two ways to get a ServletContext
 
Similar Threads
getInitParameter method in ServletContext and ServletConfig
RequestDispatcher Doubt?
getInitParameter(String str)?
getInitParamater() method
ServletContext doubt??