The include directive at first request

With the include directive, the Container has a lot of work to do, but only on the first request. From the second request on, there’s no extra runtime overhead.

  1. The client makes a request for Contact.jsp, which has not been translated. The Container reads the Contact.jsp page to start the translation process.

    image with no caption
  2. The container sees the include directive, and combines the source code of Header.jsp and Contact.jsp, and creates/translates that into a Java source file for the generated servlet.

    image with no caption
  3. The Container compiles the translated source file into a servlet class. It’s just like any other servlet at this point, and the previous step never has to happen again, unless Contact.jsp changes (or, if your Container is smart and can tell that the included Header.jsp has changed).

    image with no caption
  4. To complete the request, the Container loads the newly-compiled class, initializes a servlet (instantiates the servlet then calls init() on the new object), allocates a thread for the request, and calls the _jspService() method. From the second request on, the Container does only step (C): allocates a thread and calls the _jspService() method.

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.