Hi,
From servlet 2.1 onwards, the servlet author just overrides init() method and uses getInitParameter("name") to retieve init params configured for it.Assuming the servlet has overriden init(ServletConfig config).Which is the best way to access the init parameters ?
(This was a question in one of J2EE certification exams !)
The options are
a)config.getInitParameter("name");
b)getInitParameter("name");
c)ServletConfig.getInitParameter("name");
d)ServletContext.getServletConfig().getInitParameter("name");
-
About init(ServletConfig config) in Servlet 2.2 (1 messages)
- Posted by: Harish Madhavan
- Posted on: December 28 2003 09:35 EST
Threaded Messages (1)
- About init(ServletConfig config) in Servlet 2.2 by Viswa Cheenu on December 28 2003 10:41 EST
-
About init(ServletConfig config) in Servlet 2.2[ Go to top ]
- Posted by: Viswa Cheenu
- Posted on: December 28 2003 10:41 EST
- in response to Harish Madhavan
a)config.getInitParameter("name");
wud be the best way since the container has passed ServletConfig object to the servlet which enables you to work on the config object & obtain initparameters.
This is a direct approach.
b) wud let the superclass of ur servlet(GenericServlet) to get the refernce to ServletConfig & invoke getinitParameter();
C & D won't work since getInitParameter("name") is not a staic method. Also
ServletContext does not have a method like getServletConfig(). Actually it's the other way around.