wood burning stoves 2.0*
The moose likes Servlets and the fly likes Can i write a constructor in my servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can i write a constructor in my servlet" Watch "Can i write a constructor in my servlet" New topic
Author

Can i write a constructor in my servlet

sushindranath k
Greenhorn

Joined: Nov 30, 2006
Posts: 6
hi,


Can i write a constructor in my servlet.


Regards

sushi
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

sushindranath kkkk
Welcome to JavaRanch!

We're pleased to have you here with us in the Servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can, but you shouldn't. Firstly, if you use the wrong parameters it will never be used and will be useless, but more importantly, they don't fit with the design of servlets. If you want to initialise a servlet, place the code in the init method so it can be called by the container.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Adding another old reason.

If you pass some initialization parameter using the init-param tag in the web.xml then how would you get the handle of the servletConfig or servletContext object in the constructor.


Rahul Bhattacharjee
LinkedIn - Blog
sushindranath k
Greenhorn

Joined: Nov 30, 2006
Posts: 6
well,i want to know that when the container instatiates the servlet will it
calls a default constructor and if so of which
class constructor will it call is it HttpServlet/GenericServlet.

Regards
sushi
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

"sushindranath k",

Ben's request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

A valid last name must be used.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i write a constructor in my servlet
 
Similar Threads
can i called the constructor in servlet file?If Yes how can?If no why?
Constructor of Servlet
Destroy Method in servlet constructor
Can we write initialization code in servlet constructor
writing own constructor for servlet