Forums Register Login

basic info skipped

+Pie Number of slices to send: Send
Is it compulsory to override any method of servlet life cycle for successful compilation and execution of a particular servlet? Please reply in regards of both Servlet and HttpServlet
+Pie Number of slices to send: Send
In case of Servlet:

You have to override all the life-cylce methods viz. init(), service() and destroy().

In case of HttpServlet:

No need to override all but only the doXXX method that you are using in your client-side(JSP or HTML which will call this servlet), like doGet or doPost.This is because HttpServlet extends Generic servlet which already implements the life-cycle methods.The HttpServlet calls the service method when we call a doXXX method.


A servlet is meant to process a request.When you have a request, you have to provide a service or a doXXX method implementation in your servlet.
+Pie Number of slices to send: Send
If I were wondering this, I would create a servlet that extends HttpServlet with no methods overridden.
I would try to compile it and then I would try to deploy it.
I would see what happens.
+Pie Number of slices to send: Send
 

Originally posted by rao raghu:

You have to override all the life-cylce methods viz. init(), service() and destroy().



Are you sure about this?
Why do you think you need to override these?
Look at:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/GenericServlet.html

Are the life-cycle methods that you've mentioned declared as abstract?
[ January 19, 2007: Message edited by: Ben Souther ]
+Pie Number of slices to send: Send
ya but if you use netbeans or eclipse and if you do not override any life cycle methods than also the servlet successfully runs.....
what is the reason behind it then?
+Pie Number of slices to send: Send
Again, look at the API for the object you're extending.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html

If it implements the methods required by the Servlet interface and those methods are not declared abstract, then you do not need to override them.

Of course, if you will need to override something if you want your servlet to actually do something.
+Pie Number of slices to send: Send
Servlet is just an interface, so if you use that as the basis for your servlet you will need to implement (not override) all the lifecycle methods.
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 685 times.
Similar Threads
Is there any way to get Servlet Init Parameter using EL?
javascript, servlets and SVG
Export in Excel
Capturing Form Data
How can I change the sdk version of Websphere 4 if I already install it
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:21:59.