Name

Magic Servlet

Mistake

A single servlet performs duties of model, view, and controller, making the servlet large and difficult to maintain.

Watch for It When

Servlets are large and complicated, servlets output HTML directly, or servlets are directly connected to databases or other external resources.

Solution

Refactor into the MVC architecture. Separate all output generation into JSP pages or separate servlets. Separate calls to business data into reusable actions. Coordinate input processing, actions, and views with servlets.

Get J2EE Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.