This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Init Params doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Init Params doubt" Watch "Init Params doubt" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Init Params doubt
 
Similar Threads
getInitParameter
Doubt in Marcus Quiz-3 question
ServletConfig doubt??
accessing initialization parameters
getInitParameter() ?