• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Init Params doubt

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic