• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question regarding loading of servlet.

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding loading of servlet. Loading of servlet : The servlet container finds the servlet class mentioned in web.xml file and loads it. But when I create web project and create servlet on that, I did not touch web.xml, so how can be loading of servlet in that case.
This is simple servlet:



and my web.xml is :


 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@WebServlet.

That annotation tells the container that the servlet is accessed at the path provided.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanku very much. So in Servlet instantiation: The object of servlet class gets created in this phase. so I created web.xml here, where the object of servlet class is created? I guess it is done internally right?

 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet container creates an object of your servlet's class when it needs one. As for "where"... the servlet container is an ordinary Java application running in an ordinary JVM so that works just like creating an object in any other Java application. (Okay, it will use reflection to create that object but it's still the same process as anywhere else in Java.)
 
Gaurav Srivastav
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet class has @WebServlet("/first") annotation which do same as servlet entry in web.xml
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic