Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i write a constructor in my servlet

 
sushindranath k
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,


Can i write a constructor in my servlet.


Regards

sushi
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sushindranath k
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64852
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic