Java 如何在不使用框架的情况下创建基于 mvc 的应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18354034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to create mvc based application without using framework
提问by Murali
Struts, Spring and a few other frameworks implement the MVC architecture to separate the representation of information from the user's interaction with it.
Struts、Spring 和其他一些框架实现了 MVC 架构,以将信息的表示与用户与其交互分开。
Can any one explain or give me a link for that in Java EE?
任何人都可以在 Java EE 中解释或给我一个链接吗?
Without using a framework, how can I create an MVC application and what are the design patterns needed for that?
在不使用框架的情况下,我如何创建 MVC 应用程序以及需要哪些设计模式?
采纳答案by jeroen_de_schutter
Take a look at this presentation, which is part of Beginning & Intermediate Servlet & JSP Tutorialson http://www.coreservlets.com/
看看这个演示文稿,它是http://www.coreservlets.com/上的Beginning & Intermediate Servlet & JSP Tutorials 的一部分
回答by Bilbo Baggins
you can use Servlet and Jsp to create a MVC application without using any framework,
您可以使用 Servlet 和 Jsp 来创建 MVC 应用程序,而无需使用任何框架,
here are some useful links, http://forum.codecall.net/topic/72183-mvc-application-in-java/
这里有一些有用的链接, http://forum.codecall.net/topic/72183-mvc-application-in-java/
another useful example,
另一个有用的例子,
回答by Prasad Kharkar
I think this is a good tutorial on Creating MVC architecture with servlets and jsp
我认为这是一个关于用 servlets 和 jsp 创建 MVC 架构的好教程
The main concern in creating MVC architecture is the separation of concerns. You need to separate business layer, presentation layer and controler layer
创建 MVC 架构的主要关注点是关注点的分离。您需要分离业务层、表现层和控制层
- Model layer is achieved by simple POJO
- View layer i.e. Presentation layer can be achieved by JSP
- Controllers can be achieved by servlets in java ee
- 模型层通过简单的POJO实现
- View层即Presentation层可以通过JSP实现
- 控制器可以通过java ee中的servlets来实现
回答by Sushil Deshmukh
You can use Servlets and JSP directly. For managing Java EE applications we are using design patterns.
您可以直接使用 Servlets 和 JSP。为了管理 Java EE 应用程序,我们使用了设计模式。
MVC-1 and MVC-2 are design patterns for managing the UI layer. Struts and Spring-MVC are implementations of the MVC-2 design pattern.
MVC-1 和 MVC-2 是用于管理 UI 层的设计模式。Struts 和 Spring-MVC 是 MVC-2 设计模式的实现。
回答by Ankur Lathi
MVCstands for Model View and Controller. It is a design pattern that separates the business logic, presentation logic and data.
MVC代表模型视图和控制器。它是一种将业务逻辑、表示逻辑和数据分开的设计模式。
- Controlleracts as an interface between View and Model. Controller intercepts all the requests.
- Modelrepresents the state of the application i.e. data.
- Viewrepresents the presentaion.
- 控制器充当视图和模型之间的接口。控制器拦截所有请求。
- 模型表示应用程序的状态,即数据。
- 视图代表演示文稿。
This linkcontains an example to implement it with JSP and Servelet.
此链接包含使用 JSP 和 Servelet 实现它的示例。
回答by Mike Braun
To answer you first question: the part of the Java EE framework that implements MVC is called JSF. This provides templates, graphical components (widgets) and much more.
回答您的第一个问题:实现 MVC 的 Java EE 框架部分称为 JSF。这提供了模板、图形组件(小部件)等等。
To answer your second question: you don't really build an MVC app without any framework. You may be using Servlets and JSP, but that too is a framework. Java EE in its entirety is a (full stack) framework as well.
回答您的第二个问题:您不会真正构建没有任何框架的 MVC 应用程序。您可能正在使用 Servlet 和 JSP,但这也是一个框架。Java EE 整体上也是一个(全栈)框架。
As for the third question: this is simple, the design pattern to use for MVC is MVC.
关于第三个问题:这个很简单,MVC使用的设计模式是MVC。