I'm looking at an application that uses Jetty, and it has a lot of different related objects:
service = new Server(Integer.valueOf(System.getenv("PORT")));
final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
MyAppServlet myAppServlet = new MyAppServlet();
ServletHolder myAppServletServletHolder = new ServletHolder(myAppServlet);
final String serviceName = 'abc';
servletContextHandler.addServlet(myAppServletServletHolder, ("/"+ serviceName));
service.setHandler(servletContextHandler);
So it seems that the hierarchy is:
Server
ServletContextHandler
ServletHolder
Servlet
The meaning of a Server is obvious, and it seems that a Servlet is the script that implements the actual application.
But the meaning of ServletContextHandler is less clear. Can you give a simple explanation that doesn't assume much background in the Java ecosystem, only general programming experience? Is it for the purpose of sharing configuration variables across different applications (servlets)? What would be some useful applications of that?
Finally, I have zero clue why we need a ServletHolder instead of just giving the Servlet to the ServletContextHandler.
The following is a little related but I don't think very closely. It only has one class overlap with this question: What's the difference between a ServletHandler and a ServletContextHandler in Jetty?