任何人都可以发布或指出一个从头开始实现 Model 2 架构的清晰示例的方向吗?
以下是模型 2 的详细描述,摘自 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)
最佳答案
关于java - Java MVC 模型 2 架构的示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/970504/