|
Servlets 1.
Lifecycle of a Servlet
The servlet lifecycle consists of the following steps: Here is a simple servlet that just generates HTML. Note that HttpServlet is a subclass of GenericServlet, an implementation of the Servlet interface. The service() method dispatches requests to methods doGet(), doPost(), doPut(), doDelete(), etc., according to the HTTP request. import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("\n" + "\n" + "Hello WWW\n" + "\n" + "Hello WWW\n" + ""); } }
_________________
Muhammad Safwat Fuad The Java Code Admin Java Technical Lead. Mobile: +2010-2942-538 Email:mtv134@yahoo.com
|