O'Reilly logo

Servlets und JSPs™ von Kopf bis Fuß by Bert Bates, Kathy Sierra, Bryan Basham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.3. So sieht der Code aus (der ein Servlet zu einem Servlet macht)

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Kap02Servlet extends HttpServlet {

   public void doGet(HttpServletRequest request,
      HttpServletResponse response)
         throws IOException {

      PrintWriter out = response.getWriter();
      java.util.Date today = new java.util.Date();
      out.println("<html> " +
         "<body>" +
         "<h1 align=center>KBF Kapitel 2 Servlet</h1>" +
         "<br>" +
         today +
         "</body>" +
         "</html>");
   }
}

Im wirklichen Leben überschreiben 99,9% aller Servlets entweder die doGet()- oder die doPost()-Methode.

Beachten Sie: keine main()-Methode. Die Lebenszyklusmethoden des Servlets (wie doGet()) werden vom Container aufgerufen.

99,9999% aller Servlets sind ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required