• Post Reply Bookmark Topic Watch Topic
  • New Topic

Instaniating a Servlet

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.
 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is as good as creating instance of a class in java
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!