This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Init Params doubt" Watch "Init Params doubt" New topic

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()
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
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.
I agree. Here's the link:
subject: Init Params doubt
It's not a secret anymore!