How it looks in code (what makes a servlet a servlet)
Notice... no main() method. The servlet’s lifecycle methods (like doGet()) are called by the Container.
There are no Dumb Questions
Q: I remember seeingdoGet()anddoPost(), but on the previous page, you show aservice()method? Where did theservice()method come from?
A: Your servlet inherited it from HttpServlet, which inherited it from GenericServlet which inherited it from... ahhh, we’ll do class hierarchies to death in the Being a Servlet chapter, so you just need a little more patience.
Q: You wimped out on explaining how the containerfoundthe correct servlet... like, how does a URL relate to a servlet? Does the user have to type in the exact path and class file name of the servlet?
A: No. Good question, though. But it points to a Really Big Topic (servlet mapping and URL patterns), so we’ll take only a quick look on the next few pages, but go into much more detail later in the book (in the Deployment chapter).
With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, interactive tutorials, and more.