Prepare for your Next Interview
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]...
|
|||
|
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 |
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |