I am trying to understand Jetty.
Tell me please:
When is it better to use Servlets and when Handlers?
Can I use Connectors with Servlets for "thread-per-request model"?
In Jetty Handlers handle requests that are coming through Connectors. One of the Handlers, specifically ServletHandler
, allows Jetty to (mostly) support servlets. Servlet is a portable Java EE concept, so you can design your application in a more portable way if you use servlets in Jetty. On the other hand, they likely to bring some overhead, so you might want to implement a Handler directly that would handle requests coming via Connectors.
If you are using servlets in Jetty, you can rely on the servlet security model, on the session support, etc. If this is unnecessary for your application, you might be better off implementing a very simple handler.