wood burning stoves
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
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

Can i write a constructor in my servlet

sushindranath k

Joined: Nov 30, 2006
Posts: 6

Can i write a constructor in my servlet.


Ben Souther

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

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

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.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63841

"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.

JavaRanch Sheriff

[Asking smart questions] [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
It's not a secret anymore!