Java MVC Model 2架构的示例? [英] Examples of Java MVC Model 2 architecture?

查看:281
本文介绍了Java MVC Model 2架构的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以发布或指出我在模型2架构的从头开始实现的明确示例的方向吗?

Can anyone post or point me in the direction of a clear example of a from scratch implementation of Model 2 architecture?

以下是模型2的详细说明,取自此页

Below is a detailed description of Model 2, taken from this page.


用于设计JSP页面的Model 2体系结构实际上是应用于Web应用程序的模型视图控制器(MVC)。因此,这两个术语可以在网络世界中互换使用。 MVC起源于SmallTalk,后来进入Java社区。 Model 2 architecure及其衍生产品是所有严肃和工业强度的Web应用程序的基石,在现实世界中设计为
。因此,你必须彻底理解这种范式。图1.2显示了Model 2(MVC)架构。

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.

模型1和模型2之间的主要区别在于模型2中,控制器处理用户请求而不是另一个JSP。控制器实现为Servlet。当用户提交请求时,将执行以下步骤。

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. Controller Servlet处理用户的请求。 (这意味着JSP中的超链接应指向控制器servlet)。

  2. 然后,Controller Servlet根据请求参数(以及可选的还基于会话属性)实例化相应的JavaBeans。

  3. 然后,Controller Servlet本身或通过控制器帮助程序与中间层或直接与数据库通信以获取所需数据。

  4. Controller在以下某个上下文中设置结果JavaBeans(相同或新的) - 请求,会话或应用程序。

  5. 然后,控制器根据请求URL将请求分派到下一个视图。

  6. View使用步骤4中生成的JavaBeans来显示数据。请注意,JSP中没有表示逻辑。模型2体系结构中JSP的唯一功能是显示来自请求,会话或应用程序范围中的JavaBeans集的数据。
    MVC示例http://www.java-samples.com/images/ model2architecture.jpg

  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 http://www.java-samples.com/images/model2architecture.jpg



推荐答案

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

I like Bear Bibeault's article from a few years ago. High level explanation, but very clear.

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

This is his implementation of an MVC "framework". I learned a lot by going through it:

熊Bibeault的Frontman

这篇关于Java MVC Model 2架构的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆