Which statements are correct about the way a servlet can acces its initialization parameters?
1) By simply calling getInitParameter from any of the servlets methods (for example doGet)
2) It must be done by calling getServletConfig().getInitParaemter
3) It can only be done by overriding the method init(ServletConfig config)
4) It can be done by calling getServletContext().getInitParameter method
HttpServlet inherits from GenericServlet which implements ServletConfig and therefor has a getInitParameter() method that accesses the servlet config parameters.
As for no. 4, this calls the servlet CONTEXT init parameters, which are a totally different story...
JDBCSupport - An easy to use, light-weight JDBC framework -
2.incorrect.
- though the statement is correct, but its not a must.
note:getInitParaemter(spelling)
4. incorrect.
- when the question does not specifically mention ServletConfig or ServletContext init parameters,
the default you should consider is ServletConfig init parameters.
whereas getServletContext().getInitParameter method will return ServletContext init parameters
Himanshu Kansal wrote:Can't the reason simply be "getInitParameter" is available to the HttpServlet class from a super class in its hierarchy(GenericServlet) !
Just as I said ;)
JDBCSupport - An easy to use, light-weight JDBC framework -
"To do good, you actually have to do something." -- Yvon Chouinard
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth