Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between these methods...

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic