servlet

fun Route.servlet(path: String, servlet: HttpServlet)

Mounts a Jakarta HttpServlet at the given path within a Ktor Route.

The servlet is initialized once via HttpServlet.init, and each incoming request is translated into a KtorServletRequest/KtorServletResponse pair. The servlet's response headers, status code, and body are then forwarded back through the Ktor response pipeline. Servlet processing runs on kotlinx.coroutines.Dispatchers.IO.

Parameters

path

the URL path at which the servlet should be mounted

servlet

the Jakarta servlet instance to handle requests