Catalog / Jetty Web Server Cheatsheet
Jetty Web Server Cheatsheet
A quick reference guide for Jetty, covering configuration, deployment, and essential features. Ideal for developers and system administrators.
Jetty Basics and Configuration
Core Concepts
Jetty: A lightweight, embeddable web server and servlet container. Handlers: Components that process requests. Connectors: Components that accept incoming connections. Contexts: Represent web applications deployed in Jetty. |
Thread Pools: Manage threads for handling requests efficiently. |
Configuration Files
|
Main configuration file for Jetty. Defines server, connectors, handlers, and other settings. Located typically in |
|
Configuration file for hot deployment of web applications. Enables automatic deployment of WAR files in the |
|
Servlet configuration file for web applications. Defines servlets, filters, and other web application components. Placed inside |
Starting Jetty
From the command line:
With specific configuration:
|
Using an IDE (e.g., Eclipse, IntelliJ) by embedding Jetty. |
Deployment and Handlers
Deploying Web Applications
WAR Files |
Drop the |
Context XML |
Create a context XML file (e.g., |
Example Context XML |
|
Common Handlers
DefaultHandler: Serves static content and handles default requests. ContextHandler: Maps requests to specific contexts (web applications). ResourceHandler: Serves static resources from a specified directory. |
RequestLogHandler: Logs incoming requests to a file or other output. |
Handler Collections
Use
|
Connectors and Security
Connectors Configuration
|
Standard connector for HTTP/1.1. Configured in
|
|
Used in conjunction with
|
HTTPS Connector |
|
Security
Authentication: Jetty supports various authentication methods including Basic, Digest, and Form-based authentication. Authorization: Control access to resources based on user roles. |
SecurityHandler: Enforces security constraints defined in |
SSL Configuration
Generate a Keystore:
Configure |
Advanced Features
WebSockets
Jetty provides excellent support for WebSockets, enabling real-time bidirectional communication. Implement WebSocket endpoints using |
Example WebSocket Endpoint:
|
JNDI
JNDI Resources |
Jetty supports JNDI (Java Naming and Directory Interface) for managing resources like data sources. Configure JNDI resources in the context XML file. |
Example JNDI Configuration |
|
Logging
Jetty uses |
Configure |