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.
以下是本页的模型2的详细说明。
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.
用于设计JSP页面的Model 2体系结构实际上是应用于Web应用程序的模型视图控制器(MVC)。因此,这两个术语可以在网络世界中互换使用。 MVC起源于SmallTalk,后来进入Java社区。 Model 2 architecure及其衍生产品是现实世界中设计的所有严肃和工业强度Web应用程序的基石。因此,你必须彻底理解这种范式。图1.2显示了Model 2(MVC)架构。
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和模型2之间的主要区别在于,在模型2中,控制器处理用户请求而不是另一个JSP。控制器实现为Servlet。当用户提交请求时,将执行以下步骤。
- The Controller Servlet handles the user’s request. (This means the hyperlink in the JSP should point to the controller servlet).
Controller Servlet处理用户的请求。 (这意味着JSP中的超链接应指向控制器servlet)。
- The Controller Servlet then instantiates appropriate JavaBeans based on the request parameters (and optionally also based on session attributes).
然后,Controller Servlet根据请求参数(以及可选的还基于会话属性)实例化适当的JavaBeans。
- 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.
然后,Controller Servlet自身或通过控制器帮助程序与中间层或直接与数据库通信以获取所需数据。
- The Controller sets the resultant JavaBeans (either same or a new one) in one of the following contexts – request, session or application.
Controller在以下某个上下文中设置生成的JavaBeans(相同或新的) - 请求,会话或应用程序。
- The controller then dispatches the request to the next view based on the request URL.
然后,控制器根据请求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. MVC example http://www.java-samples.com/images/model2architecture.jpg
View使用步骤4中生成的JavaBeans来显示数据。请注意,JSP中没有表示逻辑。模型2体系结构中JSP的唯一功能是显示来自请求,会话或应用程序范围中的JavaBeans集的数据。 MVC示例http://www.java-samples.com/images/model2architecture.jpg
4 个解决方案
#1
I like Bear Bibeault's article from a few years ago. High level explanation, but very clear.
几年前我喜欢Bear Bibeault的文章。高级解释,但非常清楚。
This is his implementation of an MVC "framework". I learned a lot by going through it:
这是他对MVC“框架”的实现。通过它我学到了很多东西:
Bear Bibeault的主唱
#2
Try the Sun Java petstore:
试试Sun Java petstore:
http://java.sun.com/developer/releases/petstore/
Or an older version:
或旧版本:
http://java.sun.com/developer/releases/petstore/petstore1_3_1_02.html
#3
I would download Spring and check out some Spring examples too. Also take a look at this tutorial
我会下载Spring并查看一些Spring示例。另请参阅本教程
#4
Maybe Struts 1 (with tiles) would be easier to grok than Spring, if you want to see how MVC works in a Java web application. Ignoring all the Struts tags, you end up with Actions (which are called by the Struts servlet), JSPs and a configuration file or two to tie them together. Lots of information online.
如果你想看看MVC在Java Web应用程序中是如何工作的,那么Struts 1(带有tile)会比Spring更容易理解。忽略所有Struts标记,最终得到Actions(由Struts servlet调用),JSP和一个或两个配置文件将它们绑定在一起。网上有很多信息。
#1
I like Bear Bibeault's article from a few years ago. High level explanation, but very clear.
几年前我喜欢Bear Bibeault的文章。高级解释,但非常清楚。
This is his implementation of an MVC "framework". I learned a lot by going through it:
这是他对MVC“框架”的实现。通过它我学到了很多东西:
Bear Bibeault的主唱
#2
Try the Sun Java petstore:
试试Sun Java petstore:
http://java.sun.com/developer/releases/petstore/
Or an older version:
或旧版本:
http://java.sun.com/developer/releases/petstore/petstore1_3_1_02.html
#3
I would download Spring and check out some Spring examples too. Also take a look at this tutorial
我会下载Spring并查看一些Spring示例。另请参阅本教程
#4
Maybe Struts 1 (with tiles) would be easier to grok than Spring, if you want to see how MVC works in a Java web application. Ignoring all the Struts tags, you end up with Actions (which are called by the Struts servlet), JSPs and a configuration file or two to tie them together. Lots of information online.
如果你想看看MVC在Java Web应用程序中是如何工作的,那么Struts 1(带有tile)会比Spring更容易理解。忽略所有Struts标记,最终得到Actions(由Struts servlet调用),JSP和一个或两个配置文件将它们绑定在一起。网上有很多信息。