| Author |
Init Params doubt
|
Prakash Dwivedi
Ranch Hand
Joined: Sep 28, 2002
Posts: 452
|
|
Here is a question of JWebPlus Question ID :994874119438 Which of the following lines can be inserted at line //1 to retrieve an initialization parameter "dbname" from the init() method of a servlet? public void init() { //1 } 1.getServletConfig().getParameter("dbname"); 2.getServletConfig().getInitParameter("dbname"); 3.getServletContext().getInitParameter("dbname"); 4.getInitParameter("dbname"); 5.getInitParameterValue("dbname"); Correct Answer: 2 & 4 My doubt is here in the question it is not mentioned whether we r talking about init params of servlet or of servlet context so option 3 should also be correct. Please explain.
|
Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
|
 |
Roger Chung-Wee
Ranch Hand
Joined: Sep 29, 2002
Posts: 1683
|
|
Servlet context initialization parameters are declared for the application/context as a whole. These parameters allow an administrator or deployment developer to change specific values in the application even after it is compiled and packaged. A typical example is setting the number of connections to be maintained by a database pool. The init() method of a servlet is used to initialize a servlet, and the ServletConfig object is used by a servlet container to pass information to a servlet during initialization. So, 2 and 4 are correct.
|
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
|
 |
Sainudheen Mydeen
Ranch Hand
Joined: Aug 18, 2003
Posts: 218
|
|
Hi I would say option 3-getServletContext().getInitParameter("dbname")is also a correct answer since the question does not say "dbname" is init param of servlet or servlet context. ------------ Sainudheen
|
 |
 |
|
|
subject: Init Params doubt
|
|
|