This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes difference between these methods... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference between these methods..." Watch "difference between these methods..." New topic
Author

difference between these methods...

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
What is the differnece between below 2 methods?
a) getServletConfig().getInitParameter(str);
b) getServletContext().getAttribute(str);
Why in some code i see instead of getServletContext().getAttribute(str) ..it is coded as
getServletConfig().getServletContext().getAttribute(str);
thanks
Butch C
Greenhorn

Joined: Oct 18, 2000
Posts: 7
a) getServletConfig().getInitParameter(str);
A servlet configuration object is used to pass information
to a servlet during initialization. So this method allows
the servlet to pull in parameters from the config file which
contains name/value pairs. The str portion is the name of
the parameter, you will get back the value which is stored
in the file. This method is used to configure the servlet.

b) getServletContext().getAttribute(str);

This method returns the attribute named in str from the servlet
context. These attributes are global for the context. The
main use for this is to allow access to an object across all
servlets or if you are using JSPs and you want the object to
be of scope="application" then call setAttribute(str) on the
servlet context.
Hope this helps...
 
 
subject: difference between these methods...