• 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

constructors

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i pass object as parameters in parameterised constructor .?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A servlet needs a no-arg constructor, so the container can instantiate it.
If you were to provide a parameterized constructor only, the container wouldn't know how to call it to instantiate the servlet, so that won't work.
You could define a parameterized constructor along side an explicit no-arg constructor, but it would never be called so that is pretty much useless.
Luckily, though, after the container has created an instance of a servlet it calls a life cycle method named init() to which it passes an instance of ServletConfig.
Using this ServletConfig instance you can retrieve initialization parameters, by name. These parameters can be defined in the web.xml deployment descriptor.
It may seem like a bit of a hassle, but that would be the way to provide a servlet with the parameters it needs to initialize itself.
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic