• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dbt on getServletConfig()

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call it, but it will return null, as the servlet config has not been initialized yet.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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



Check ServletsFaq
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic