Good day!
I am reading Head First Servlets and JSP and it says that 99% of servlets make use of the HttpServlet. What is the other 1%? And it says that in the real world, 99.9% of all servlets override either that doGet() or doPost() method. What is the other 0.1%? Or it isn’t worth mentioning that’s why the book didn’t mention it?
Thank you.
The 1% doesn’t make use of abstract
HttpServletclass. So they useServletinterface without extendingHttpServlet.Currently in the Java EE API, there’s only one other
Servletwhich does that: theFacesServletwhich is the core controller behind the Java EE provided MVC framework JavaServer Faces (JSF). JSF enables you to skip all the tedious process and the boilerplate code which is necessary to gather, convert and validate parameters, update the model values and invoke specific action methods.But at the time of writing this book, the author likely didn’t realize that. As of now, JSF certainly doesn’t account for only 1%. In theory it’s possible to implement
Servletfor other protocols than HTTP, like FTP. This is not provided by the standard Java EE API, but there are some 3rd party "FtpServlet" classes out. And I believe some Portlet APIs also use a non-HttpServletclass (they just implementServletand don’t extendHttpServlet).As to the HTTP methods, next to HTTP
GETandPOSTthere are alsoHEAD,PUT,OPTIONS, etc. But I think 0.1% is heavily underestimated. TheHEADis definitely much more often used, think of servletcontainer’s ownDefaultServlet(like as Tomcat has). TheHEADplays an important role in browser cache requests. But when it comes to "homegrown" servlets, then it are indeedGETandPOSTwhich gets the lone attention.See also: