Java EE vs JSP vs JSF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23707036/
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
Java EE vs JSP vs JSF
提问by Oliver Spryn
I am looking to learning a Java technology for developing web applications. As I looked more into this, I became confused between jsf, jsp, and javaee. I know there are several posts on SO (post 1, post 2) which attempt to resolve these confusions, I have a few more on top of them:
我正在学习一种用于开发 Web 应用程序的 Java 技术。当我深入研究这一点时,我对jsf、jsp和javaee感到困惑。我知道 SO 上有几篇文章(第1 篇、第2 篇)试图解决这些困惑,我还有一些关于它们的文章:
- Is JSP "dead" in favor of JSF?
- Is Java EE the platform JSF runs on top of or something different altogether?
- Is JSF merely an MVC framework for developing web applications?
- Is JSF a framework developed by Oracle and part of Java, or is it a separate framework altogether (Much like the Zend Framwork is from PHP)?
- [Bonus] Would you recommend learning jspor jsf?
- JSP 是否“已死”而支持 JSF?
- Java EE 是运行在 JSF 之上的平台还是完全不同的东西?
- JSF 仅仅是用于开发 Web 应用程序的 MVC 框架吗?
- JSF 是由 Oracle 开发的框架和 Java 的一部分,还是完全是一个单独的框架(很像 Zend 框架来自 PHP)?
- [Bonus] 你会推荐学习jsp还是jsf?
In your answer, feel free to compare any of these technologies to things like ASP.NET, ASP.NET MVC, Ruby on Rails, Zend Framework, or regular-old Java Applets, as these are things I am already familiar with.
在您的回答中,请随意将这些技术中的任何一项与 ASP.NET、ASP.NET MVC、Ruby on Rails、Zend Framework 或常规的 Java Applets 之类的东西进行比较,因为这些是我已经熟悉的东西。
Thank you for your time.
感谢您的时间。
采纳答案by Evandro Pomatti
Is JSP "dead" in favor of JSF?
JSP 是否“已死”而支持 JSF?
JSF has countless benefits over JSP. For instance:
JSF 比 JSP 有无数的好处。例如:
- It defines a MVC approach
- It set up componentization standards
- It has apply values feature
- Built-in AJAX
- A defined view context control
- Allows for rich interfaces extensions like Primefaces
- 它定义了一种 MVC 方法
- 它建立了组件化标准
- 它具有应用值功能
- 内置 AJAX
- 定义的视图上下文控件
- 允许丰富的接口扩展,如 Primefaces
And we can go on and on.
我们可以继续下去。
You can still use JSP for other scenarios where you need some specific flexibility or performance, and the same thing for servlets, but JSF pretty much replaced JSP for "robust" applications.
您仍然可以将 JSP 用于需要特定灵活性或性能的其他场景,对于 servlet 也是如此,但 JSF 几乎取代了 JSP 用于“健壮”应用程序。
Now, I am a huge fan of JSF, but it has a long way to go. JSF 2.2 kinda looks like a mature framework now that it has a defined navigation standard(FacesFlow), and we just had a built-in file uploader in 2.1 and it is not even AJAX, and there's "HTML5", etc. So yeah, there is a lot more work to be done that I won't detail in here.
现在,我是 JSF 的忠实粉丝,但它还有很长的路要走。JSF 2.2 看起来有点像一个成熟的框架,因为它有一个定义的导航标准( FacesFlow),而且我们在 2.1 中有一个内置的文件上传器,它甚至不是 AJAX,还有“HTML5”等。所以是的,还有很多工作要做,我不会在这里详述。
In my experience, JSP is in fact "dead" if compared to JSF and other frameworks like Spring MVC and others. Java EE 7 tutorial barely says anything about JSP. But it is not dead dead, since it is already supported in Web Containers and you can still use it.
根据我的经验,如果与 JSF 和 Spring MVC 等其他框架相比,JSP 实际上是“死的”。Java EE 7 教程几乎没有提及 JSP。但它并没有死,因为它已经在 Web Containers 中得到支持,你仍然可以使用它。
Is Java EE the platform JSF runs on top of or something different altogether?
Java EE 是运行在 JSF 之上的平台还是完全不同的东西?
JSF is part of Java EE but you do not need full Java EE profile in order to use JSF. Examples:
JSF 是 Java EE 的一部分,但您不需要完整的 Java EE 配置文件即可使用 JSF。例子:
- Tomcat is just a Java EE Web Profile implementation, and you can use JSF in Tomcat.
- You can use JSF in JBoss but you do not need JMS enabled in order to JSF to work.
- Tomcat 只是一个 Java EE Web Profile 实现,你可以在 Tomcat 中使用 JSF。
- 您可以在 JBoss 中使用 JSF,但您不需要启用 JMS 来使 JSF 工作。
Java EE components are modular, and you only need a Web Profile server/container in order to use JSF.
Java EE 组件是模块化的,您只需要一个 Web Profile 服务器/容器即可使用 JSF。
Is JSF merely an MVC framework for developing web applications?
JSF 仅仅是用于开发 Web 应用程序的 MVC 框架吗?
Yes (but I wouldn't say merely). Each one has it own pros and cons. But the principle is the same.
是的(但我不会仅仅说)。每一种都有自己的优点和缺点。但原理是一样的。
One could argue about integration with EJB, but so is Spring MVC with its own container.
人们可能会争论与 EJB 的集成,但 Spring MVC 及其自己的容器也是如此。
Is JSF a framework developed by Oracle and part of Java, or is it a separate framework altogether (Much like the Zend Framwork is from PHP)?
JSF 是由 Oracle 开发的框架和 Java 的一部分,还是完全是一个单独的框架(很像 Zend 框架来自 PHP)?
Oracle now delegates to teams to define specification. In theory, you can implement your own JSF if you want. I do not know about PHP's Zend Framework.
Oracle 现在委托团队来定义规范。理论上,您可以根据需要实现自己的 JSF。我不知道 PHP 的 Zend 框架。
Most common JSF implementations are Mojarra and MyFaces. (Luiggi beat me on this right now, you can check his links).
最常见的 JSF 实现是 Mojarra 和 MyFaces。(Luiggi 现在在这点上打败了我,你可以查看他的链接)。
[Bonus] Would you recommend learning jsp or jsf?
[Bonus] 你会推荐学习jsp还是jsf?
I would recommend both. JSP first and JSF after it.
我会推荐两者。首先是 JSP,然后是 JSF。
But I would 100% recommend you to use JSF for you projects. But make sure you understand componentization and all the stuff that makes JSF a powerful tool.
但我会 100% 建议您为您的项目使用 JSF。但是请确保您了解组件化以及使 JSF 成为强大工具的所有内容。
Also check out JSF 2.2 new features, this page is awesome for an intro on the latest features added to the framework.
另请查看JSF 2.2 新功能,此页面非常适合介绍添加到框架中的最新功能。
回答by Luiggi Mendoza
Is JSP "dead" in favor of JSF?
JSP 是否“已死”而支持 JSF?
No, it is still maintained for legacy and current web applications as view technology. Also, JSF works with JSP as view, but since JSF 2 it is better to use Facelets as the technology view. The reasons are explained here: Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?. In short, Facelets supports pre and post processing of the content to render, while JSP doesn't.
不,它仍然作为视图技术为遗留和当前的 Web 应用程序维护。此外,JSF 使用 JSP 作为视图,但从 JSF 2 开始,最好使用 Facelets 作为技术视图。原因在这里解释:为什么从 JSF2.0 开始,Facelets 比 JSP 更受欢迎作为视图定义语言?. 简而言之,Facelets 支持对要呈现的内容进行预处理和后处理,而 JSP 不支持。
Is Java EE the platform JSF runs on top of or something different altogether?
Java EE 是运行在 JSF 之上的平台还是完全不同的东西?
JSF can run by its own in any Java web application server. You just need to add the necessary libraries: JSF-api and JSF-impl.
JSF 可以在任何 Java Web 应用程序服务器中自行运行。您只需要添加必要的库:JSF-api 和 JSF-impl。
Is JSF merely an MVC framework for developing web applications?
JSF 仅仅是用于开发 Web 应用程序的 MVC 框架吗?
Yes. It doesn't provide any help for web service generation, connection pooling, transaction management, etc. It supports EJB injection through @EJB
and parameters injection through @ManagedProperty
, but that's all. You may use other frameworks to do the job: Hibernate, EJB, Spring, CDI, etc.
是的。它不为Web 服务生成、连接池、事务管理等提供任何帮助。它支持EJB 注入@EJB
和参数注入@ManagedProperty
,仅此而已。您可以使用其他框架来完成这项工作:Hibernate、EJB、Spring、CDI 等。
Is JSF a framework developed by Oracle and part of Java, or is it a separate framework altogether (Much like the Zend Framwork is from PHP)?
JSF 是由 Oracle 开发的框架和 Java 的一部分,还是完全是一个单独的框架(很像 Zend 框架来自 PHP)?
JSF is supported by by JSR 344. This specification is supported by the Java Community Process, which is supported by Oracle. From this, you can infer that at least Oracle provides an implementation for JSF. Since JSF is a specification, it can be implemented by other organizations as well. Currently, there's another implementation for JSF, MyFaces.
JSF 由JSR 344支持。该规范由 Oracle支持的Java Community Process支持。由此可以推断,至少 Oracle 为 JSF 提供了一个实现。由于 JSF 是一种规范,因此其他组织也可以实现它。目前,还有另一个 JSF 实现,MyFaces。
This is like asking should I learn how to create HTML or how to use a library set that will create HTML for me?. JSP is a technology made for the view of web applications that supports dynamic content by usage of Java technology. JSF is a MVC framework that helps you to ease the generation of the content in view (JSP or Facelets) and data binding through the view, controller and the model. You can learn both at the same time, and I recommend you to learn what you're currently using or what you will use. IMO you should learn both: JSF to develop JSF applications, and JSP to work with other MVC frameworks or to maintain current legacy applications built with JSP.
这就像问我应该学习如何创建 HTML 或如何使用将为我创建 HTML 的库集?. JSP 是一种通过使用Java 技术支持动态内容的Web 应用程序视图的技术。JSF 是一个 MVC 框架,可帮助您简化视图(JSP 或 Facelets)中内容的生成以及通过视图、控制器和模型进行数据绑定。您可以同时学习两者,我建议您学习当前使用的或将使用的。IMO 您应该同时学习:用于开发 JSF 应用程序的 JSF,以及用于与其他 MVC 框架一起工作或维护使用 JSP 构建的当前遗留应用程序的 JSP。
回答by Dima
1.Is JSP "dead" in favor of JSF?
1.JSP“死”了,支持JSF吗?
In the realm of JAVA EE JSP is announced "obsolete". In a wider world it is well alive.
在 JAVA EE JSP 领域宣布“过时”。在更广阔的世界里,它是活生生的。
2.Is Java EE the platform JSF runs on top of or something different altogether?
2. Java EE 是运行在 JSF 之上的平台还是完全不同的东西?
Depends on where is the "top". Servlets are the basement for most Java frameworks including JSF.
取决于“顶部”在哪里。Servlet 是大多数 Java 框架(包括 JSF)的基础。
3.Is JSF merely an MVC framework for developing web applications?
3.JSF仅仅是一个开发web应用的MVC框架吗?
Yes, it the sense that JSF is a presentation layerframework.
是的,JSF 是一个表示层框架。
4.Is JSF a framework developed by Oracle and part of Java, or is it a separate framework altogether (Much like the Zend Framwork is from PHP)?
4.JSF 是 Oracle 开发的框架,是 Java 的一部分,还是完全独立的框架(很像 Zend 框架来自 PHP)?
JSF is an official part of Java EE 7 by Oracle.
JSF 是 Oracle 的 Java EE 7 的官方部分。
5.[Bonus] Would you recommend learning jsp or jsf?
5.[Bonus] 你会推荐学习jsp还是jsf?
Both, to a certain depth. Consider also HybridJava - its is same powerful as JSF but about twice simpler.
两者,到一定深度。也考虑 HybridJava - 它与 JSF 一样强大,但大约简单两倍。