JavaOmnibus
J2EE Front Controller
J2EE pattern • Presentation
J2EEPresentationJava example

Front Controller solves a specific structural problem in the design.

Route all web requests through one central entry point.

Pattern overview

J2EE pattern

Route all web requests through one central entry point.

Intent

Provide a single handler that centralizes routing, security, locale, and shared web concerns.

Problem

Request handling logic is scattered across many endpoints with duplicated setup behavior.

Solution

Send requests through a central controller that delegates to commands or handlers.

Fit and tradeoffs

FamilyJ2EE
CategoryPresentation
Best used when
  • For MVC-style web applications or API gateways inside a monolith.
Tradeoffs
  • The controller must not become a giant switch statement.

Java example

This example is intentionally compact so the pattern shape stays easy to see.

@WebServlet("/*")
public final class AppFrontController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        if (request.getRequestURI().equals("/orders")) {
            request.getRequestDispatcher("/WEB-INF/orders.jsp").forward(request, response);
            return;
        }
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

Related pages

Keep exploring