This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can i called the constructor in servlet file?If Yes how can?If no why?
 
Similar Threads
init and destroy.
Dbt on getServletConfig()
Why do we have init() method in Servlets ?
Can we write initialization code in servlet constructor
Servlet's constructor