Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What acts in the role of the 'main method' in a servlet?

Tags:

java

servlets

Servlet is also java program but there is no main method in servlet.Who will take role of main method on servet.

like image 291
giri Avatar asked Jan 07 '10 05:01

giri


People also ask

What are the main methods used with servlets?

Methods of Servlet interface The init, service and destroy are the life cycle methods of servlet.

What is the function of main method?

When the Java interpreter executes an application (by being invoked upon the application's controlling class), it starts by calling the class's main method. The main method then calls all the other methods required to run your application.

Which are two main methods of servlet?

There are two main types of Servlet. They are Generic and HTTP servlets. We can use the constructor method to initialize the Servlets with the help of init() and the destructor method to remove the servlet from the resources using destroy().

Where is main method in Java web application?

There is no "main" method (as in application entry point) in web applications, since each servlet is an independent entry point.


1 Answers

Servlets are designed to run inside a servlet container (eg. Apache Tomcat). Execution of a servlet happens in the following manner: The servlet container calls the GenericServlet.service() method on a servlet which typically calls the appropriate doXxx() method, eg. doGet(), doPost(), etc. The doXxx() method is responsible for interpreting the HTTP request and serving an appropriate response. GenericServlet.service() is roughly analagous to main() in a plain old java class.

like image 175
Asaph Avatar answered Sep 19 '22 05:09

Asaph