Jetty: servlets vs handlers

Edward83 picture Edward83 · Nov 12, 2010 · Viewed 7.4k times · Source

I am trying to understand Jetty.

Tell me please:

  1. When is it better to use Servlets and when Handlers?

  2. Can I use Connectors with Servlets for "thread-per-request model"?

Answer

Olaf picture Olaf · Jun 21, 2011

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.