It's not a secret anymore!*
The moose likes Servlets and the fly likes can i called the constructor in servlet file?If Yes how can?If no why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "can i called the constructor in servlet file?If Yes how can?If no why?" Watch "can i called the constructor in servlet file?If Yes how can?If no why?" New topic
Author

can i called the constructor in servlet file?If Yes how can?If no why?

dev pandya
Greenhorn

Joined: Jun 10, 2008
Posts: 14
can i called the constructor in servlet?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

A servlet is a Class, so yes you can call the constructor. The servlet is designed to run inside a container, however, and the container only knows how to interact with the servlet in certain ways, and it also expects the servlet to behave in particular ways in response to those interactions.

Servlets are not supposed to use constructors, so while while it is valid it is not really a 'servlet' thing to do.
[ June 11, 2008: Message edited by: David O'Meara ]
 
Consider Paul's rocket mass heater.
 
subject: can i called the constructor in servlet file?If Yes how can?If no why?
 
Similar Threads
Can we write initialization code in servlet constructor
init and destroy.
Dbt on getServletConfig()
Why do we have init() method in Servlets ?
Servlet's constructor