java - Java MVC 模型 2 架构的示例?

标签 java model-view-controller web-applications servlets

任何人都可以发布或指出一个从头开始实现 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.

  1. The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet).
  2. The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes).
  3. 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.
  4. The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application.
  5. The controller then dispatches the request to the next view based on the request URL.
  6. 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. MVC example
    (source: java-samples.com)

最佳答案

我喜欢Bear Bibeault's 几年前的文章。高级解释,但非常清楚。

这是他实现的一个MVC“框架”。我通过它学到了很多东西:

Bear Bibeault's Frontman

关于java - Java MVC 模型 2 架构的示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/970504/

相关文章:

java - 如何在 Tomcat 8 中设置 Java 运行时参数

java - 未知错误 : Chrome failed to start: crashed(selenium , headless 模式)

javascript - 在 mvc View 中检索数据

java - postgresql:如何存储用户密码?

java - 在 Google 工作表中插入日期并在单元格中附加 '

java - 使用 OpenJPA 加载时,数据库中的时间戳和实体中的 java.util.Date 会导致舍入问题

javascript - backbone.js this._configure 在调用 View 时未定义

java - 在 MVC 上的一个 Jframe 中有多个带有按钮的 Jpanel,如何在我的 Controller 中获取 actionlistener?

javascript - AngularJS:创建映射到 REST 资源的对象(ORM 样式)

html - ios 10 中的 apple-mobile-web-app-status-bar-style