The HTML for the initial form page

The HTML is simple—it puts up the heading text, the drop-down list from which the user selects a beer color, and the submit button.

image with no caption

Q:

Q: Why is the form submitting to “SelectBeer.do” when there is NO servlet with that name? In the directory structures we looked at earlier, I didn’t see anything that had the name “SelectBeer.do”. And what’s with the “.do” extension anyway?

A:

A: SelectBeer.do is a logical name, not an actual file name. It’s simply the name we want the client to use! In fact the client will NEVER have direct access to the servlet class file, so you won’t, for example, create an HTML page with a link or action that includes a path to a servlet class file.

The trick is, we’ll use the XML Deployment Descriptor (web.xml) to map from what the client requests (“SelectBeer.do”) to an actual servlet class file the Container will use when a request comes in for “SelectBeer.do”. For now, think of the “.do” extension as simply part of the logical name (and not a real file type). Later in the book, you’ll learn about other ways in which you can use extensions (real or made-up/logical) in your servlet mappings.

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.