Model 2
Model 2 is a complex design pattern to separate display (display of content) and logic (input and manipulation of the content) in Java - Web applications . Hence it is commonly associated with MVC . Although the exact design of MVC has never been specified for Model 2, a number of publications recommend a formalized layer that contains the MVC model code. For example, the Java BluePrints originally recommended the use of EJBs to encapsulate the MVC model.
In a Model 2 application requests from the client - browser directed to the controller. The controller executes the logic necessary to obtain the content for the display. Then he stores this content in the request (usually as JavaBean or POJO ) and decides which view to hand over the request. The view then displays the content that was submitted by the controller.
Model 2 is recommended for medium and large applications.
history
In 1998, Sun Microsystems published a preliminary version of the JSP specification, version 0.92. It lists two methods by which JSP pages can be used. The first model ("Model 1" according to the order in the document) was simple, JSP pages were separate entities. Logic could be contained in the page itself, the navigation between the pages was usually realized by hyperlinks . ColdFusion and Active Server Pages are examples of contemporary technologies that implemented this model.
The second model (Model 2 in order) was an improved method that combines Servlet - with JSP technology. The difference listed was that a servlet would intercept the request, pack the content to be displayed into a parameter (usually a JavaBean), and finally call a JSP to display the content in the desired output format. This model differed from the previous one in the fact that JSP technology was used as a pure template engine . All logic was separated in a servlet so that the sole job of the JSP was to render the provided content .
In 1999, Govind Seshadri succeeded in formalizing the term Model 2 as an MVC architecture pattern for web applications, instead of one of two options. Given the relocation of the logic from the JSP to a servlet, these two could be viewed as the view and controller of an MVC architecture.
In March 2000, Apache Struts was released. This project formalized the separation between View and Controller and claimed to be an implementation of the Model 2 pattern. Once again, the implementation of the "model" remained undefined with the expectation that developers would fill it with an appropriate solution. Database interaction via JDBC and EJBs was an option suggested on the Struts homepage. Hibernate , iBATIS, and Apache OJB were later listed as more modern options for the model.
A number of competing frameworks have appeared since Struts was released. Many of them also claim that they implement Model 2 and MVC. The result is that the two terms are used interchangeably by developers, which has led to the name "MVC Model 2" or "MVC2".
misunderstandings
A common misconception is that a formalized MVC pattern is a prerequisite for a Model 2 implementation. However, the Java BluePrints specifically warn against this interpretation:
The literature on Web-tier technology in the J2EE platform frequently uses the terms "Model 1" and "Model 2" without explanation. This terminology stems from early drafts of the JSP specification, which described two basic usage patterns for JSP pages. While the terms have disappeared from the specification document, they remain in common use. Model 1 and Model 2 simply refer to the absence or presence (respectively) of a controller servlet that dispatches requests from the client tier and selects views.
In German translation:
The literature on web tier technology for the J2EE platform often uses the terms "Model 1" and "Model 2" without explanation. This technology comes from early drafts of the JSP specification, which describes two basic utility models for JSP pages. Although the terms have disappeared from the specification document, they remain common. Model 1 and Model 2 simply refer to the absence or presence of a controller servlet that sends requests from the client tier and selects views.
Furthermore, the term "MVC2" has led to the misconception that Model 2 is the next generation of MVC. In fact, MVC2 is just an abbreviation of "MVC Model 2".
See also
- Apache Struts enables web applications based on a Model 2 architecture.
- JavaServer Faces is also a variant of the Model 2 architecture.
Individual evidence
- ↑ JSP 0.92 Specification
- ↑ Understanding JavaServer Pages Model 2 architecture by Govind Seshadri (JavaWorld)
- ↑ How Struts Implements Model 2 (The Origins of Model 1 / Model 2) (PDF; 745 kB)
- ↑ Struts 1.x Homepage ( Memento of the original from September 23, 2010 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.
- ↑ Java BluePrints 4.4.1: Structuring the Web Tier
- ↑ Struts, an open-source MVC implementation
- ↑ Archived copy ( Memento of the original from June 22, 2012 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.