Home

This Chapter
-Introduction
-Why Servlets Are Not Dead
-The Problems with Model 1
-Model 2
-The Benefits of Struts
-Overview of the Chapters
-Code Download
-Other Resources

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Model 2

The second design model is simply called Model 2. This is the recommended architecture to base your Java Web applications on. Model 2 is another name for the Model-View-Controller (MVC) design pattern. In Model 2, there are three main components in an application: the model, the view, and the controller. The MVC pattern is further discussed in Chapter 1.

Note

The term Model 2 was first used in the JavaServer Pages Specification version 0.92.

In Model 2, you have one entry point for all pages and usually a servlet acts as the main controller and JSPs for the presentation. Compared to Model 1, Model 2 applications enjoy the following benefits.

Now, you see why servlets and JSPs are used together.

Note

One question commonly asked: if there is only one servlet for the whole application and this is the only entry to the application, doesn’t the performance suffer. Does the servlet container spawn many instances of the servlet? The answer is the container only creates one servlet instance, unless you implement the javax.servlet.SingleThreadModel interface (not recommended and has been deprecated in Servlet 2.4) and performance does not suffer. For more detailed discussion, see my book How Tomcat Works.

Previous
Next