Issue
Can anyone post or point me in the direction of a clear example of a from scratch implementation of Model 2 architecture?
Below is a detailed description of Model 2, taken from this page.
The Model 2 architecture for designing JSP pages is in reality, Model View Controller (MVC) applied to web applications. Hence the two terms can be used interchangeably in the web world. MVC originated in SmallTalk and has since made its way into Java community. Model 2 architecure and its derivatives are the cornerstones for all serious and industrial strength web applications designed in the real world. Hence it is essential for you understand this paradigm thoroughly. Figure 1.2 shows the Model 2 (MVC) architecture.
The main difference between Model 1 and Model 2 is that in Model 2, a controller handles the user request instead of another JSP. The controller is implemented as a Servlet. The following steps are executed when the user submits the request.
- The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet).
- The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes).
- The Controller Servlet then by itself or through a controller helper communicates with the middle tier or directly to the database to fetch the required data.
- The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application.
- The controller then dispatches the request to the next view based on the request URL.
- The View uses the resultant JavaBeans from Step 4 to display data. Note that there is no presentation logic in the JSP. The sole function of the JSP in Model 2 architecture is to display the data from the JavaBeans set in the request, session or application scopes.
(source: java-samples.com)
Solution
I like Bear Bibeault's article from a few years ago. High level explanation, but very clear.
This is his implementation of an MVC "framework". I learned a lot by going through it:
Answered By - Jibba