Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dbt on getServletConfig()

 
Suchitra Bhat
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

My dbt is that what happens if i call getServletConfig() from the constructor of the servlet ? Its given in the HFSJ that it can be called from any where in my code . According to my understanding getServletconfig() returns null when called from constructor of the servlet so that getServletConfig().getInitParameter() throws null pointer exception if called from the constructor.

Some one please justify this or if it returns illegalState Exception.

thanks in advance,
Suchitra
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suchitra Bhat:
Hi All,

My dbt is that what happens if i call getServletConfig() from the constructor of the servlet ? Its given in the HFSJ that it can be called from any where in my code . According to my understanding getServletconfig() returns null when called from constructor of the servlet so that getServletConfig().getInitParameter() throws null pointer exception if called from the constructor.

Some one please justify this or if it returns illegalState Exception.

thanks in advance,
Suchitra


Hi,

The Servlet init() method is called after the servlets constructor is called. Only during init() method the initParameters are placed into the ServletConfig. So, I think we cannot use getServletConfig().getInitParameter() to retrieve parameters from the ServletConfig in the constructor.

Thanks
Chandu
 
Suchitra Bhat
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

But my dbt is can we call getServletconfig() from the constructor and what does it return when caled from constructor?

Regards,
Suchitra
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call it, but it will return null, as the servlet config has not been initialized yet.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But my dbt is can we call getServletconfig() from the constructor


Check ServletsFaq
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic