JSP 与 Velocity 哪个更好?
JSP和Velocity哪个更好 - 表现 - 使用方便 - 轻松创建可重用组件 - 开源第三方的可用性 - IDE支持
What is better between JSP and velocity in
- Performance
- Ease of use
- Ease of creating reusable components
- Availability of open source 3rd parties
- IDE support
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
速度甚至更好 FreeMarker。
在 JSP 中,您不能 pojo 层次结构的运行时调度而且一切都是静态类型的,这很痛苦。 此外,如果您创建许多 JSP2.0 自定义标记(例如超过 100-150 个),那么您的开发部署周期将由于 Jasper 无法有效解决依赖关系而严重减慢。
另一方面,JSP 有很好的工具支持。
慢速JSP编译参考:
http://www.mailinglistarchive.com/ [电子邮件受保护]/msg10786.html
http://marc.info/?l= tomcat-dev&m=119377083422720&w=2
Velocity or even better FreeMarker.
In JSP you cannot have runtime dispatch for pojo hierarchies and everything is statically typed which is a pain. Moreover if you create many JSP2.0 custom tags (say more than 100-150) then your development-deployment cycle will slow down heavily due to inefficiencies of Jasper to resolve dependencies efficiently.
On the other hand JSP has great tool support.
slow JSP compilation references:
http://www.mailinglistarchive.com/[email protected]/msg10786.html
http://marc.info/?l=tomcat-dev&m=119377083422720&w=2
我将重点关注模板引擎的使用,因为这是我最有经验的。
这取决于你真正想做什么。 Servlet 与 Velocity(或 FreeMarker)相结合,提供了逻辑和表示的非常好的分离。 模板更难测试,因为您需要评估模板才能判断 HTML(或任何其他输出格式)是否正确。 对于 JSP,这可以在您选择的 IDE 中完成。
模板的一大优点是您可以将它们完全存储在应用程序之外,甚至可以在应用程序运行时更新它们。 这对于 JSP 来说有点困难,尽管热部署已经非常接近了。
可以使用模板引擎的包含功能来创建可重用的组件。
I'll focus on using a template engine, because that is what I have most experience with.
It depends on what you really want to do. Servlets in combination with Velocity (or FreeMarker for that matter) offer a very good seperation of logic and presentation. Templates are harder to test, because you would need to evaluate the template to be able to judge wheter the HTML (or whatever else the output format is) is correct. For JSP this can be done in your IDE of choice.
The big advantage of templates is that you can store these completely outside of your application and even update them while your application is running. This is something that is a little harder to do with JSP, although hot deployment comes pretty close.
Reusable components can be created by using the include functionality of the template engine.
从工程师的角度来看,上述 Velocity 的优点忽略了一些非常重要的事情:
示例
link
与 JSP 相比,后两项确实使 Velocity 更加有用。
The advantages of Velocity as per above miss a couple of very important things from the engineers perspective:
example
link
Those last two really make Velocity useful compared to JSP.
我不知道Velocity是否能在各方面与JSP竞争,但Velocity更快,更容易。Velocity的效率高出35%到45%,如果是复杂的网页,可能会减少,但仍然高出5%比JSP。
I don't know whether Velocity can be able to compete with JSP in all aspects but Velocity is faster and nuch easier.Efficiency of Velocity is 35 to 45% more if it is complicated webpages it may be reduced but still it is 5% more than JSP.
速度比较好
它适应许多应用领域
它为模板设计者提供了简单、清晰的语法
它为开发人员提供了一个简单的编程模型
由于模板和代码是分开的,您可以独立开发和维护它们
Velocity 引擎可以轻松集成到任何 Java 应用程序环境中,尤其是 servlet
Velocity 使模板能够访问上下文中数据对象的任何公共方法
Velocity is better
It adapts to many application areas
It offers a simple, clear syntax for the template designer
It offers a simple programming model for the developer
Because templates and code are separate, you can develop and maintain them independently
The Velocity engine easily integrates into any Java application environment, especially servlets
Velocity enables templates to access any public method of data objects in the context
@Vartec:
我不认为“视图与业务逻辑的严格分离”是 jsp 中不存在的速度特性。 您可以(或多或少)在 jsp 中执行业务逻辑,但根本不建议这样做。 但我同意你关于语法的观点。
性能
JSP被编译为Java,所以我不认为速度更快。 (我自己没有做过基准测试)
易于使用
对于设计师:速度
对于程序员:(恕我直言)jsp,因为它更接近代码
易于创建可重用组件
JSP 有很多组件
Velocity 本身没有组件(不是面向组件的)
开源第 3 方的可用性
我见过比 Velocity 使用 JSP 或 JSP 相关技术的项目要多得多。 也许是因为速度真的很低......:-)
IDE 支持
有很多用于 jsp 的工具。 特别是eclipse jboss插件/工具套件有一个很好的jsp编辑器。
Velocity 的插件大多没有功能或非常基本(如果有语法突出显示,那你就很幸运)
更新
如果您现在正在寻找模板引擎,我建议您看看 thymeleaf。 它的速度相对轻量级,可以仅使用几行代码来模板化一些基于文本的模板,或者用作全功能模板引擎,例如在 Web 应用程序中。
@Vartec:
I don't think that the "strict separation of view from business logic" is a velocity feature that is not present in jsp. You can do business logic in jsp (more or less) but it's not recommended at all. But I agree in your point regarding the syntax.
Performance
JSP is compiled to Java, so I don't think that velocity is faster. (have not done benchmarks myself)
Ease of use
For designers: velocity
For programmers: (IMHO) jsp, because it's closer to code
Ease of creating reusable components
JSP has lots of components
Velocity has no components itself (not component oriented)
Availability of open source 3rd parties
I have seen far more projects using JSP or JSP related technologies than velocity. Maybe because velocity is really low level... :-)
IDE support
There are plenty of tools for jsp. Especially the eclipse jboss plugin/tool suite has a good jsp editor.
Plugins for Velocity are mostly not functional or pretty basic (you get lucky if you have syntax highlighting)
Update
If you are looking for a templating engine now, I'd suggest to have a look at thymeleaf. It's comparably lightweight to velocity and can be used just to template some text based templates with a few lines of code or used as a full featured templating engine for example within a webapp.
Velocity 的优点:
Advantages of Velocity:
下面是关于 Freemarker 的内容,但比较可能仍然具有相关性。
在这两种技术的开发过程中,选择其中一种技术的主要原因似乎是:
原因,但似乎影响不大:
Freemarker 示例:
JSP-EL-JSTL 示例:
The below is about Freemarker, but the comparisons are probably still relevant.
At this point in these two technologies' development, it seems like the primary reasons to choose one over the other are:
Reasons that don't seem to have as much of an impact:
Freemarker Example:
JSP-EL-JSTL Example: