JSP 与 Velocity 哪个更好?

发布于 2024-07-14 10:26:48 字数 72 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

相权↑美人 2024-07-21 10:26:49

速度甚至更好 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

凉月流沐 2024-07-21 10:26:49

我将重点关注模板引擎的使用,因为这是我最有经验的。

这取决于你真正想做什么。 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.

遇到 2024-07-21 10:26:49

从工程师的角度来看,上述 Velocity 的优点忽略了一些非常重要的事情:

  • 视图与业务逻辑的严格分离(如上所述)
  • 图形设计人员可以理解的简单语法(如上所述)
  • 紧凑的代码,不太复杂稍后重温的噩梦,请参阅
    示例
    link
  • 非 servlet 容器部署意味着在任何地方都可以轻松部署

与 JSP 相比,后两项确实使 Velocity 更加有用。

The advantages of Velocity as per above miss a couple of very important things from the engineers perspective:

  • strict separation of view from business logic (as above)
  • simple syntax that can be understood by graphic designers (as above)
  • compact code that is less of a nightmare to revisit later, see
    example
    link
  • non-servlet container deployment means easy deploy anywhere

Those last two really make Velocity useful compared to JSP.

太阳公公是暖光 2024-07-21 10:26:49

我不知道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.

烟柳画桥 2024-07-21 10:26:49

速度比较好
它适应许多应用领域
它为模板设计者提供了简单、清晰的语法
它为开发人员提供了一个简单的编程模型
由于模板和代码是分开的,您可以独立开发和维护它们
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

童话里做英雄 2024-07-21 10:26:48

@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.

淡笑忘祈一世凡恋 2024-07-21 10:26:48

Velocity 的优点:

  • 视图与业务逻辑严格分离
  • 图形设计师可以理解的简单语法

Advantages of Velocity:

  • strict separation of view from business logic
  • simple syntax that can be understood by graphic designers
如此安好 2024-07-21 10:26:48

下面是关于 Freemarker 的内容,但比较可能仍然具有相关性。

在这两种技术的开发过程中,选择其中一种技术的主要原因似乎是:

  1. 您需要一种特定的东西,而不是另一种技术
  2. 您希望阻止视图开发人员将 Java scriptlet 放入其中JSP 页面
  3. 与其他原因相比,您的开发人员更喜欢其中一个

原因,但似乎影响不大:

  1. 速度。 典型的 Java EE 应用程序中有很多层,它们的影响比视图渲染器可能花费的几毫秒的时间要大得多。 事实上,如果我的应用程序性能低于标准,这可能是我要解决的最后一层。
  2. IDE 支持。 JBoss Tools提供了Freemarker编辑器,JSP工具也是众所周知的。
  3. 句法。 由于 EL 和 JSTL,JSP 2 和 Freemarker 对于许多基本操作具有几乎相同的语法。

Freemarker 示例:

<#list foos as foo>
  <tr>
     <td>${foo.field1}</td>
     <td>${foo.field2}</td>
     <td>
        <#list foo.childObjects as child>
           <#if child.name == 'bar'>
              ${child.value}
           </#if>
        </#list>
     </td>
  </tr>
</#list>

JSP-EL-JSTL 示例:

<c:forEach items="${foos}" var="foo">
  <tr>
     <td>${foo.field1}</td>
     <td>${foo.field2}</td>
     <td>
        <c:forEach items="${foo.childObjects}" var="child">
           <c:if test="${child.name == 'bar'}">
              ${child.value}
           </c:if>
        </c:if>
     </td>
  </tr>
</c:forEach>

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:

  1. There is something specific that you need that is in one and not the other
  2. You want to prevent view developers from putting Java scriptlets into JSP pages
  3. Your developers are more comfortable in one than the other

Reasons that don't seem to have as much of an impact:

  1. Speed. There are so many layers in a typical Java EE app that have a much greater impact than the couple of milliseconds more or less that a view renderer might take. In fact, this is probably the last layer I would tackle if my app was performing subpar.
  2. IDE support. JBoss Tools provides a Freemarker editor, and JSP tools are well known.
  3. Syntax. JSP 2 and Freemarker have virtually identical syntax for many basic operations, because of EL and JSTL.

Freemarker Example:

<#list foos as foo>
  <tr>
     <td>${foo.field1}</td>
     <td>${foo.field2}</td>
     <td>
        <#list foo.childObjects as child>
           <#if child.name == 'bar'>
              ${child.value}
           </#if>
        </#list>
     </td>
  </tr>
</#list>

JSP-EL-JSTL Example:

<c:forEach items="${foos}" var="foo">
  <tr>
     <td>${foo.field1}</td>
     <td>${foo.field2}</td>
     <td>
        <c:forEach items="${foo.childObjects}" var="child">
           <c:if test="${child.name == 'bar'}">
              ${child.value}
           </c:if>
        </c:if>
     </td>
  </tr>
</c:forEach>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文