aspose file tools*
The moose likes Servlets and the fly likes why we cant't use constructor for initializing servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

why we cant't use constructor for initializing servlet

vikasBhai kachaveDon
Greenhorn

Joined: Jan 18, 2007
Posts: 1
why we cant't use constructor for initializing servlet
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can, you just shouldn't.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

The init() method is typically used to perform Servlet initialization its creating or loading objects that are used by the servlet.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
moreover objects like servletconfig would not be available in the constructor.


Rahul Bhattacharjee
LinkedIn - Blog
soban babuvasahan
Greenhorn

Joined: Jan 18, 2007
Posts: 1
if you create a constructor you must take care of methods other methods service()or destroy so better you use as it is..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This question has been asked many times here.
Search this forum with keyword 'constructor' and you will find dozens of thread; each repeating the same basic conversation.

It is also answered in our ServletsFaq
[ January 18, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: why we cant't use constructor for initializing servlet