Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
If we want to make a database connection for getting data. We would ideally want it to happen only once when first time the servlet is loaded and not that everytime we call the servlet the database connection happens. If we do the same in constructor, the connection will be made each time the servlet is instantiated.
Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
We can force the servlet container to create more than one instace of a servlet class. This can be done through providing different initialization values in the diployment discriptor for the same servlet. This values will be available for init() method.
why why why do you care? It is just the convention than simplifies creating the servlet instance by having a no-args constructor. See the java.lang.Class class - especially think about how easy it is to do:
Servlet s = Class.forName( servletname ).newInstance();
Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
LXI Technologies P Ltd
[url]www.lxisoft.com[/url]
Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |