// Created by Jarticles.com:09/17/00, feel free to use /** * This class gives you an idea of how the Servlet Engine works. */ public class SimpleServletEngine { public static void main(String args[]) throws Exception { if (args.length <= 0) { System.out.println("Usage: java SimpleServletEngine javaClassName"); System.exit(0); } System.err.println("loading class " + args[0] + "..."); Class cls = Class.forName(args[0]); Servlet servlet = (Servlet) cls.newInstance(); servlet.init(); servlet.service(); } } /** * A class that extends Servlet interface directly. */ class MyServlet implements Servlet { public void init() { System.out.println("Calling MyServlet init()..."); } public void service() { System.out.println("I'm MyServlet"); } } /** * A class that extends HttpServlet,thus implementing Servlet * interface automatically. */ class AnotherServlet extends HttpServlet { public void service() { System.out.println("I'm AnotherServlet"); } } /** * An abstract class HttpServlet implementing Servlet Interface. */ abstract class HttpServlet implements Servlet { public void init() { System.out.println("Calling HttpServlet init()..."); } // not implemented yet public abstract void service(); } /** * Servlet Interface */ interface Servlet { public void init(); public void service(); }