java JSP 和 Facelets 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2197139/
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
What are the differences between JSP and Facelets?
提问by Alex Ntousias
I just started reading the Java EE 6 Tutorial, and I'm a little confused! I knew about JavaServer Pages (JSP), and even did some coding during my undergraduate studies. But now, in this tutorial, I don't see anything about JSP.
我刚刚开始阅读Java EE 6 教程,我有点困惑!我了解 JavaServer Pages (JSP),甚至在我的本科学习期间做过一些编码。但是现在,在本教程中,我没有看到有关 JSP 的任何内容。
Instead I read about Facelets, a new View Definition Framework (as it is described in this tutorial). I searched a little bit over the Internet to clarify the distinction between JSP and Facelets, and I came across with this postthat helped me a lot (especially BalusC's answer). But these terms are still a little unclear to me.
相反,我阅读了 Facelets,一个新的视图定义框架(如本教程中所述)。我在 Internet 上进行了一些搜索以澄清 JSP 和 Facelets 之间的区别,我发现这篇文章对我有很大帮助(尤其是BalusC 的回答)。但是这些术语对我来说仍然有点不清楚。
What is the difference between JSP and Facelets? Are Facelets going to replace JSP, or is it just a technology that works better with JSF (and if it's the latter, why)? If they are different, when should I use each one of them?
JSP 和 Facelets 有什么区别?Facelets 是要取代 JSP,还是只是一种更适合 JSF 的技术(如果是后者,为什么)?如果它们不同,我应该什么时候使用它们中的每一个?
采纳答案by Adeel Ansari
As you can read from the tutorial,
正如你可以从教程中读到的,
The term Facelets is used to refer to the JavaServerTM Faces View Definition Framework, which is a page declaration language that was developed for use with JavaServer Faces technology. As of JavaServer Faces 2.0, Facelets is a part of JavaServer Faces specification and also the preferred presentation technology for building JavaServer Faces based applications.
术语 Facelets 用于指代 JavaServerTM Faces 视图定义框架,它是一种页面声明语言,开发用于 JavaServer Faces 技术。从 JavaServer Faces 2.0 开始,Facelets 是 JavaServer Faces 规范的一部分,也是构建基于 JavaServer Faces 的应用程序的首选表示技术。
Now, JSP is the standard view technology for the web. But when it comes to adopt JSF as a web framework, JSP doesn't support all the features provided in JSF 2.0. Therefore, there was a need of some standard view technology to work with JSF 2.0. So, Facelets is just that.
现在,JSP 是 Web 的标准视图技术。但是当谈到采用 JSF 作为 Web 框架时,JSP 并不支持 JSF 2.0 中提供的所有功能。因此,需要一些标准的视图技术来与 JSF 2.0 一起工作。所以,Facelets 就是这样。
If you are not working with JSF at all, you don't need to employ Facelets. You can go with JSP in that case. Or there are few other template frameworks, like FreeMarker, and Velocity. Moreover, some web frameworks, defines there own mark-up, like Struts2. So if you decided to go with Struts, using Struts mark-up is the way to go.
如果您根本不使用 JSF,则不需要使用 Facelets。在这种情况下,您可以使用 JSP。或者很少有其他模板框架,例如 FreeMarker 和 Velocity。此外,一些 Web 框架定义了自己的标记,例如 Struts2。因此,如果您决定使用 Struts,那么使用 Struts 标记是正确的选择。

