title: Examples of Java MVC Model 2 architecture?
body: <p>Can anyone post or point me in the direction of a clear example of a <strong>from scratch</strong> implementation of Model 2 architecture?</p>
  
  <p>Below is a detailed description of Model 2, taken from <a href="http://www.java-samples.com/showtutorial.php?tutorialid=350" rel="nofollow noreferrer">this page</a>.</p>
  
  <blockquote>
    <p>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. </p>
    
    <p>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. </p>
    
    <ol>
    <li>The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet). </li>
    <li>The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes). </li>
    <li>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. </li>
    <li>The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application. </li>
    <li>The controller then dispatches the request to the next view based on the request URL. </li>
    <li>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.
    <a href="https://i.stack.imgur.com/imowO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/imowO.jpg" alt="MVC example"></a><br>
    <sub>(source: <a href="http://www.java-samples.com/images/model2architecture.jpg" rel="nofollow noreferrer">java-samples.com</a>)</sub>  </li>
    </ol>
  </blockquote>