But I still didnt get how the Servlet is instantiated(??).
Another question : Can we run the servlet in command line using 'java MyServlet'
Servlets must run inside a "servlet container" that provides the vital services of creating a servlet instance, receiving a request, holding session data, etc. etc etc.
That said - with thoughtful architecture you can put the main functional parts of your servlet application into classes that can be run from the command line with the aid of a little interface code.
I'll give you an example - the parameters in a request can be obtained as a Map with getParameterMap(). This Map has entries keyed by the parameter name and with parameter value(s) in a
String[]
If you write your processing code in a method that can take a Map like this, and write output to a PrintWriter, then the same code that runs in the servlet can be run outside the servlet environment.
Bill