Servlets are designed to be used inside the operating environment of a JEE web application container. The container provides considerable infrastructure, plus it routes traffic to and from the servlet.
There are 2 reasons I can think of for wanting to run servlet code from a command line:
1. You have some sort of function you wish to use but you want to be able to invoke it via a batch process instead of by way of a web request.
2. You want to test the code in the servlet as part of an offline test suite.
For reason 1, you have a couple of options. If you want the actual servlet to function, use a command-line based utility such as wget to send a request to the server and retrieve the request results. If you want the logic but don't want to have a web server running, the same general rules as reason 2 apply.
For reason 2, where you don't want to talk to a running server, you can set up a batch server simulation such as the Cactus test tool. Cactus can imitate much of the infrastructure that an application server provides, but it's quicker to launch, since it's not a full-blown web server.
If you just want logic functionality, the best thing to do is to move the business logic itself outside of the servlet class and into a POJO business-object class. Then you can have the servlet invoke its functionality for online use, or invoke it directly for offline use.
Customer surveys are for companies who didn't pay proper attention to begin with.
subject: how to call servlet class and it's methods from shell script