There is no main method in the Java servlet no more than the ActionListener in Swing JButton has the main method. They both have methods that you can connect to when a specific event occurs (for example, clicking on a JButton or an HTTP PUT request on an HttpServlet). And in both cases, you are provided with information about the event that caused the call - ActionEvent for JButton and ServletRequest for servlet.
Thinking about servlets in terms of event handlers is probably more useful than trying to think of them as a separate Java application, where you are responsible for the entire control flow.
mattjames
source share