Mapping the logical name to a servlet class file

  1. Diane fills out the form and hits submit. The browser generates the request URL:

    image with no caption
  2. The Container searches the DD and finds a <servlet-mapping> with a <url-pattern> that matches /SelectBeer.do, where the slash (/) represents the context root of the web app, and SelectBeer.do is the logical name of a resource.

    image with no caption
  3. The Container sees that the <servlet-name> for this <url-pattern> is “Ch3 Beer”. But that isn’t the name of an actual servlet class file. “Ch3 Beer” is the name of a servlet, not a servlet class!

    To the Container, a servlet is something named in the DD under a <servlet> tag. The name of the servlet is simply the name used in the DD so that other parts of the DD can map to it.

  4. The Container looks inside the <servlet> tags for something with the <servlet-name> “Ch3 Beer”.

    image with no caption
  5. The Container uses the <servlet-class> in the <servlet> tag to know which servlet class is responsible for handling this request. If the servlet has not been initialized, the class is loaded and the servlet is initialized.

  6. The Container starts a new thread to handle the request, and passes the request to the thread (to the servlet’s service() method).

  7. The Container sends the ...

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.