This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
hi Generally constructors are for initializing instance variables. but in servlets we are using Life cycle method init(ServletConfig sc) for getting initialization parameters.As servlet is instantiated by container is this the reason we are not writing our own constructor in servlet? if not what is the reason please explain if we pass our own constructor what will be the containers and servlet reaction thanks in advance saiprasanna
If your servlet class has a constructor with parameters, it will never be called by the servlet container.
If your servlet class has a public arg-less constructor, it will be called.
Generally speaking, instance variables one might use in a servlet are related to the servlet environment - for example initialization parameters read from web.xml. Therefore they should be initialized in init as per the API.
Incorrect use of servlet instance variables is the cause of many beginner problems. Bill
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: constructors are for initializing instance variables