Menu

Showing posts with label Servlet. Show all posts
Showing posts with label Servlet. Show all posts

Can we have multiple doGet() or doPost() in a servlet?

 No, it doesn't make sense to creating multiple doGet() or doPost() methods in a Servlet. The compiler will always execute the first one. It's better to write a different Servlet to handle the different requests.


One other way is the method overriding, we can override doGet() or doPost() in any of the methods viceversa. For more read Overriding Service, Get, and Post

Why there is no main method in Servlet?

A Java Servlet is a plugin to a web server and always run in web container.

When we run any program that has main method, the program runs the web server with the help of main method. And a web server runs the Servlet.