Geeks Talk

Prepare for your Next Interview




Constructors in servlet concept

This is a discussion on Constructors in servlet concept within the JSP forums, part of the Web Development category; There is any constructors in servlet concept, plz tell me? NOTE : [This question was asked by venukairi]...


Go Back   Geeks Talk > Web Development > JSP

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-11-2007
Expert Member
 
Join Date: Oct 2006
Posts: 690
Thanks: 0
Thanked 49 Times in 41 Posts
JobHelper is on a distinguished road
Constructors in servlet concept

There is any constructors in servlet concept, plz tell me?

NOTE : [This question was asked by venukairi]
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-11-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 76 Times in 64 Posts
psuresh1982 will become famous soon enough
Re: Constructors in servlet concept

we can use constructor in servlet for initialization , also you can write your own constructors. For example

class sample extends HttpServlet
{
sample()
{
System.out.println("I am Constructor in servlet");
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
sample obj=new sample();
}
}

--------------------
suresh
Reply With Quote
  #3 (permalink)  
Old 01-11-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 8 Times in 7 Posts
vmshenoy is on a distinguished road
Re: Constructors in servlet concept

hi


Yes, of course you can use the constructor instead of init(). There's nothing to stop you. But you shouldn't. The original reason for init() was that ancient versions of Java couldn't dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won't have access to a ServletConfig or ServletContext. Plus, all the other servlet programmers are going to expect your init code to be in init(). Why confuse them?


Bye

__________________
:)
NEVER SAY DIE.
Reply With Quote
Reply

  Geeks Talk > Web Development > JSP


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
why we shift Servlet to JSP ? psuresh1982 JSP 5 06-30-2008 09:09 AM
Want to know the Concept StephenRaj Unix/Linux 4 01-12-2007 07:54 AM
Path for storing JSP or servlet files JobHelper JSP 1 01-05-2007 12:48 PM
Concept in .NET JohnMathew ASP.NET 2 10-09-2006 04:25 PM
Does default constructors gets created in all scenario RyanJames C and C++ 1 07-12-2006 05:34 PM


All times are GMT -4. The time now is 05:00 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved