Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

why we cant't use constructor for initializing servlet

 
vikasBhai kachaveDon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
why we cant't use constructor for initializing servlet
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
You can, you just shouldn't.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
The init() method is typically used to perform Servlet initialization its creating or loading objects that are used by the servlet.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Report post to moderator
moreover objects like servletconfig would not be available in the constructor.
 
soban babuvasahan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
    Bookmark Topic Watch Topic
  • New Topic