Forums Register Login

Instaniating a Servlet

+Pie Number of slices to send: Send
This may be a stupid question but still :

If i write a Servlet

class Kiran extends HttpServlet
{

}

If i do this from another servlet or from any java class.

Kiran k = new Kiran()

Will the servlet will get invoked by the container and its init() would be called ??
+Pie Number of slices to send: Send
No it won't. The only thing that should be instantiating servlets is the container itself. Servlets respond to requests; if you wan't to use some servlet functionality send it a request.
+Pie Number of slices to send: Send
Thanks Paul.
+Pie Number of slices to send: Send
it is as good as creating instance of a class in java
+Pie Number of slices to send: Send
 

Surya Kanth wrote:it is as good as creating instance of a class in java


Actually, it is exactly the same. Servlets are Java classes so they act just like Java classes.
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 742 times.
Similar Threads
from form to servlet to jsp
Thred Safety when Injecting an EJB into servlet using @EJB
Interface
DB connection from servlets
Integarting existing jsps and Servlets Web Application with Spring 3.0
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:51:47.