How it works...

The Java EE server itself will call doGet() or doPost() methods, depending on the HTTP method used by the caller. In our recipe, we are redirecting them both to the same doRequest() method.

The init() method belongs to the servlet life cycle managed by the server and is executed as a first method after the servlet instantiation.

The destroy() method also belongs to the servlet life cycle and it's executed as the last method before the instance deallocation.

Get Java EE 8 Cookbook 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.