Skip to Content
Head First Servlets and JSP, 2nd Edition
book

Head First Servlets and JSP, 2nd Edition

by Bryan Basham, Kathy Sierra, Bert Bates
March 2008
Intermediate to advanced
911 pages
20h 31m
English
O'Reilly Media, Inc.
Content preview from Head First Servlets and JSP, 2nd Edition

The HTTP request Method determines whether doGet() or doPost() runs

The client’s request, remember, always includes a specific HTTP Method. If the HTTP Method is a GET, the service() method calls doGet(). If the HTTP request Method is a POST, the service() method calls doPost().

image with no caption

HTTP requests

image with no caption

You probably won’t care about any HTTP Methods except GET and POST

Yes, there are other HTTP 1.1 Methods besides GET and POST. There’s also HEAD, TRACE, OPTIONS, PUT, DELETE, and CONNECT.

All but one of the eight has a matching doXXX() method in the HttpServlet class, so besides doGet() and doPost(), you’ve got doOptions(), doHead(), doTrace(), doPut(), and doDelete(). There’s no mechanism in the servlet API for handling doConnect(), so it’s not part of HttpServlet.

But while the other HTTP Methods might matter to, say, a web server developer, a servlet developer rarely uses anything but GET and POST.

For most (or probably all) servlet development, you’ll use either doGet() (for simple requests) or doPost() (to accept and process form data), and you won’t have to think about the others.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates
Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 9780596516680Errata PageSupplemental Content