Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JSP Model 2 is an MVC architecture for Java web applications: a servlet acts as the controller, model components handle business state and operations, and a JSP renders the view. A browser request reaches the servlet first; the servlet validates input, calls the appropriate model or service, places results in request or session scope, and forwards to a JSP that generates the HTML response.

What JSP Model 2 means

Model 2 separates a Java web application into three responsibilities:

  • Model: business data, rules, state, and operations such as database access or shopping-cart updates.
  • View: a JSP page that formats data as HTML.
  • Controller: usually a Java Servlet that receives requests, coordinates model work, manages navigation, and selects the next view.

Oracle describes the arrangement as one in which servlets control application flow and delegate business logic to external components, commonly JavaBeans or Enterprise JavaBeans, while JSP pages generate browser HTML. Model 2 is therefore a servlet-and-JSP implementation of MVC, not a separate replacement for either technology.

How a request flows through Model 2

  1. The browser sends an HTTP request. A link, form, or script issues a GET or POST to a URL mapped to a controller servlet.
  2. The controller interprets the request. The servlet reads parameters, identifies the requested operation, validates input, and applies request-level security and routing checks.
  3. The controller invokes the model. It calls a business service, JavaBean, data-access object, shopping-cart component, or EJB-backed operation. The model queries or changes business state without generating page markup.
  4. The controller prepares data. Results, validation messages, and view-specific values are placed in an appropriate scope, normally request scope for one response or session scope for state that must survive multiple requests.
  5. The controller chooses a view. It forwards internally to a JSP, redirects to another URL when a new request is required, or returns an error response.
  6. The JSP renders the response. The JSP reads the attributes prepared by the controller, combines them with HTML and presentation tags, and sends the resulting markup to the browser.

Forward versus redirect

An internal forward keeps processing on the server and lets the JSP use the attributes placed in the current request. A redirect instructs the browser to issue a new request, which changes the URL and is commonly used after a successful POST to prevent duplicate form submission. The controller, rather than the JSP, makes this navigation decision.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Java Servlet & JSP Cookbook
  • Used Book in Good Condition

What belongs in each layer

Model: business state and rules

The model represents the application’s domain and the operations allowed on it. Examples include a shopping cart, catalog service, database-access object, or EJB-backed service. It owns validation that expresses business rules, persistence interaction, calculations, and state changes. Keeping these operations outside the JSP makes them reusable from other controllers and independently testable.

Controller: request handling and coordination

The servlet controller defines application behavior at the HTTP boundary. It maps URLs to actions, converts and validates user input, invokes model operations, handles outcomes and errors, stores attributes, and selects a JSP or redirect. It should coordinate the work rather than become a second location for all business rules.

Rank #2
Sale
Murach's Java Servlets and JSP (3rd Edition): Java Programming Book for Web Development with Tomcat, NetBeans IDE, MySQL, JavaBeans & MVC Pattern - Guide to Building Secure Applications
  • Series: Murach: Training & Reference
  • Paperback: 758 pages
  • Language: English
  • ISBN-10: 1890774782, ISBN-13: 978-1890774783
  • Product Dimensions: 8 x 1.7 x 10 inches, Shipping Weight: 3.4 pounds

View: presentation only

The JSP formats already-prepared data. Expression Language, JSTL, and custom tags are preferred for dynamic presentation because they keep looping, conditional display, and formatting readable without embedding request processing or business calls in the page. A JSP should not decide which database operation to run or implement the application’s navigation policy.

JSP Model 1 versus Model 2

The key difference is where request processing and navigation live.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Comparison Model 1 Model 2
Request processing Usually performed directly in the JSP Performed by a servlet controller
Business calls Often mixed into page code Delegated to model or service components
Presentation and logic Closely coupled Separated between JSP, controller, and model
Navigation Page code commonly decides the next response Controller selects the view or redirect
JSP scriptlets More likely as processing grows Usually limited or eliminated in favor of EL and tags
Testing Page-mixed logic is harder to test in isolation Model and controller code can be tested separately from rendering
Components and configuration Fewer moving parts for a small page More classes, mappings, and coordination
Best fit Very small, simple pages Applications with meaningful workflows or business processing

Model 1 can be quick for a simple form or demonstration. As validation, authentication, persistence, and navigation accumulate, the same JSP becomes difficult to maintain. Model 2 adds a controller and model boundary, so it requires more structure and configuration, but that structure prevents presentation changes from being entangled with application behavior.

Why a JSP is also a servlet at runtime

A JSP is a server-side page technology, not an independent execution environment. The JSP container translates the page into a Java servlet class, compiles it when necessary, loads it, and uses that servlet to service requests. The generated class implements the JSP page contract defined by the Jakarta Server Pages specification. Containers commonly retain the compiled servlet in memory for subsequent requests, recompiling when the page changes according to container rules.

This implementation detail explains why a JSP can access request, session, application, and other servlet-related objects. It does not change the architectural role of the page: in Model 2, the generated servlet is the implementation mechanism for the view, while the explicitly mapped application servlet remains the controller.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Where Struts fits

Apache Struts is a prominent historical example of Model 2. Its ActionServlet and RequestProcessor supplied controller responsibilities, while JSP pages and tag libraries supplied the view. Struts helped standardize dispatch and form handling, but it is not a requirement for Model 2. Modern Jakarta EE applications and other Java frameworks may use front controllers, annotations, filters, dependency-injected services, or different view technologies while preserving the same separation of controller, model, and view.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical Model 2 design checklist

  • Map the browser URL to a servlet or front controller.
  • Validate syntax and required fields at the request boundary.
  • Pass business decisions and persistence work to model or service classes.
  • Use request scope for data needed only by the selected response; use session scope only for genuinely conversational state.
  • Expose view-ready attributes instead of database connections or internal persistence objects when possible.
  • Keep JSP pages focused on markup, EL, JSTL, and presentation formatting.
  • Use a forward for server-side view rendering and a redirect when the browser should make a new request.
  • Handle model errors explicitly and provide a defined error view or HTTP status.

When Model 2 is the right choice

Model 2 is most useful when an application has multiple screens, nontrivial navigation, authentication, validation, persistence, or business rules that must be maintained over time. It is not a claim of automatic performance superiority: the cited documentation does not establish a universal numeric speed advantage. Its principal benefit is organization—business and request-processing code can evolve and be tested separately from HTML rendering.

Quick Recap

SaleBestseller No. 1
Java Servlet & JSP Cookbook
Java Servlet & JSP Cookbook
Used Book in Good Condition
$15.41
SaleBestseller No. 2
Murach's Java Servlets and JSP (3rd Edition): Java Programming Book for Web Development with Tomcat, NetBeans IDE, MySQL, JavaBeans & MVC Pattern - Guide to Building Secure Applications
Murach's Java Servlets and JSP (3rd Edition): Java Programming Book for Web Development with Tomcat, NetBeans IDE, MySQL, JavaBeans & MVC Pattern - Guide to Building Secure Applications
Series: Murach: Training & Reference; Paperback: 758 pages; Language: English; ISBN-10: 1890774782, ISBN-13: 978-1890774783
$40.62
Bestseller No. 3
Murach's Java Servlets and JSP, 2nd Edition
Murach's Java Servlets and JSP, 2nd Edition
Used Book in Good Condition
$6.84

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.