Hi,
Can we define Constructors in servlets and if we can then
how can we call it?
one more thing is can we define methods in Jsp file..
Regards,
Chandu.
-
Defining Constructor In Servlets (5 messages)
- Posted by: chandrasekhar ch
- Posted on: December 05 2003 05:21 EST
Threaded Messages (5)
- Defining Constructor In Servlets by Sudhir Byna on December 05 2003 06:41 EST
- Defining Constructor In Servlets by Burak AKSOY on December 05 2003 10:39 EST
- Defining Constructor In Servlets by Paul Strack on December 05 2003 12:00 EST
- Defining Constructor In Servlets by Viswa Cheenu on December 07 2003 08:55 EST
- Constructor in servlets by Bharat Kumawat on July 23 2004 05:15 EDT
-
Defining Constructor In Servlets[ Go to top ]
- Posted by: Sudhir Byna
- Posted on: December 05 2003 06:41 EST
- in response to chandrasekhar ch
You can define methods in JSP, the same way as u declare variables.
<%!..%> -
Defining Constructor In Servlets[ Go to top ]
- Posted by: Burak AKSOY
- Posted on: December 05 2003 10:39 EST
- in response to chandrasekhar ch
Probably you don't need that. Why do you want to do this? -
Defining Constructor In Servlets[ Go to top ]
- Posted by: Paul Strack
- Posted on: December 05 2003 12:00 EST
- in response to Burak AKSOY
If you want to define a constructor in a servlet, you can only define a no-parameter constructor. In general, most developers don't do this. Typically, they put construction-type logic in the servlet's init() method instead. -
Defining Constructor In Servlets[ Go to top ]
- Posted by: Viswa Cheenu
- Posted on: December 07 2003 08:55 EST
- in response to chandrasekhar ch
You can't define constructors for your servlet since the servlets are initialized by the container. Would give you compilation error. -
Constructor in servlets[ Go to top ]
- Posted by: Bharat Kumawat
- Posted on: July 23 2004 05:15 EDT
- in response to chandrasekhar ch
One can definitely have constructor in servlet.Even you can user the constrctor in servlet for initialization purpose,but this type of approch is not so common.You can perform common operations with the constructor as you normally do.The only thing is that you cannot call that constructor explicitly by the new keyword as we normally do.In the case of servlet, servlet container is responsible for instentiating the servlet, so the constructor is also called by servlet container only.