Looking at an Example Servlet

Servlets are conceptually simple. You configure your Web server to map a certain URL path to a Java class (different servers do this differently). The Java class needs to extend HttpServlet and handle one of several methods: doGet, doPost, doPut, or doDelete. (doGet or doPost are used most commonly.)

These messages reflect the various ways that servlets are invoked by a GET, POST, PUT, or DELETE HTTP request from a client (although DELETE is rare). The servlet is responsible for setting the mime type, error code, cookies, and other status information about the request, as well as returning the content.

Let's say that the path /baseballstats has been mapped to the class BaseBallStatServlet. This is a class that knows ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.