java - MVC 和 MVC Model2 之间的实际区别是什么

标签 java model-view-controller

只是想知道MVC和MVC Model2在开发上的实际区别是什么

最佳答案

为了说明前面的答案(并添加来自 this article 的解释):

MVC2 是一个 abuse of language实际上指的是 JSP 模型 2 体系结构,而不是 JSP 模型 1:

The first Java technology for server-side web development was the servlet.
Writing applications with servlets was very similar to writing CGI applications in Perl in that all of the output had to be built up as Strings from within Java code.
This was very tedious and error-prone. It also made it very difficult for web designers with no Java experience to alter the look and feel of the pages generated by servlets.

alt text
(来源:javaworld.com)

Then came JSP. JSPs, like Microsoft ASPs and like the popular scripting language PHP, treat everything as template text, but allow the insertion of Java code into tags called scriptlets and JSP expressions.
This allowed people to work on server-side applications just as they would with the other popular scripting languages but it had a couple of drawbacks.

  • There was no separation of concerns.
  • One script would hold database code, business logic, HTML markup and any javascript code needed for the final page rendering.
  • Code reuse was difficult as was automated testing.

This came to be known as "Model 1" JSP programming.

MVC or the Model View Controller pattern was a common technique for separating the various concerns in GUI code invented by Trygve Reenskaug, working on Smalltalk for Zerox.

At some point it became clear that this technique could be adapted to Java EE applications to achieve the same level of separation.
Doing so involves writing the Model layer as Beans or Plain Old Java Objects (POJOs), using servlets as the Controller, and then, when all the heavy lifting is done, forwarding to a JSP to format and markup the results.
Servlet/JSP applications written using and MVC architecture came to be known as Model 2 JSP programming.

alt text
(来源:javaworld.com)

Because this pattern existed in a different form before being used in servlet/JSP applications, it was sometimes referred to as "MVC2". This name led to some confusion as it implied that there is an MVC1 for servlet applications, which there is not.
It is sufficient just to say MVC.

关于java - MVC 和 MVC Model2 之间的实际区别是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/796508/

相关文章:

java - 在 Windows : xperf: error: NT Kernel Logger: Invalid flags. (0x3ec) 上运行 xperfasm JMH 探查器时出错

java - 删除 META-INF 文件夹

java - 如何在 Spring 处理 400,404,500,501 等?

xml - 带有 XML 的 Spring 3 REST 给出 "406 Not Acceptable"

java - 清除数组中的方法

java - 如何从我的应用程序调用测试方法?

java - 无法从位置加载对象,错误子报告 jasper

java - MVC项目结构验证类(java)

javascript - 为什么我的 session 值针对特定值发生了变化?

java - 动态填充 thymeleaf 中的列表