File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "constructors" Watch "constructors" New topic
Author

constructors

Slaxmi Raj
Ranch Hand

Joined: Apr 20, 2012
Posts: 40
how can i pass object as parameters in parameterised constructor .?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1761
    
    7

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.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructors