File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference between these methods..." Watch "difference between these methods..." New topic

difference between these methods...

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) is coded as
Butch C

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...
I agree. Here's the link:
subject: difference between these methods...
It's not a secret anymore!