As you learned in the last hour, servlets are an underlying technology behind JavaServer Pages. Because of the close relationship, it's useful to learn something about servlets. Understanding servlets will help you in your study of JSPs by helping you understand what is going on under the hood. Even if you do most of your work with JSPs, you will be more effective at writing JSPs and debugging problems if you can understand the servlet code. In addition, JSPs and servlets have distinct and complementing roles in Web applications. More often than not, you will find yourself using a combination.
Servlets allow the programmer to work directly with requests made to a Web server and to form responses that include content that is returned to a client. Unlike JSPs, which are oriented toward presentation, with their combination of HTML and scriptlets or other elements, servlets are composed entirely with Java. As you might expect, servlets are great for performing lower-level functions that work with data or implement business models.