1

似乎velocity 和freemarker 看起来相当相似,至少对于基本用法而言。

无论如何,所谓的“内置”或标准视图框架是什么?看起来像:

<c:if test="${someobject.property != null}">
4

2 回答 2

6

它很可能是JSTL使用的统一表达式语言 (EL)

我认为它看起来更像

<c:if test="${someobject.property != null}">
于 2010-02-25T22:37:10.220 回答
5

那确实是JSTL。但是它不是内置的,但您需要做的就是将jstl-1.2.jar放入其中/WEB-INF/lib并根据 TLD 文档在 JSP 页面顶部声明其标记库之一,例如JSTL 核心

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

这样您就可以使用链接中列出的标签。大多数核心标签只是流控制标签。JSTL 也有XMLSQL标记库,但它们仅用于快速原型制作,不应在实际生产中使用。然后是Format (fmt) taglib,它非常适合国际化和本地化(i18n 和 l10n)。最后是有用的函数 (fn) taglib,它提供了简单的 EL 函数。

然后是${}事情。这称为表达语言。它只是在 Javabean 的任何页面、请求、会话和应用程序范围内访问“后端数据”(属性),就像借助PageContext#findAttribute()和调用 Javabean getters一样。如果您了解scriptlets,那么您将了解以下示例:

${user.address.street}

大致可以解决

<%= pageContext.findAttrubute("user").getAddress().getStreet() %>

EL 是nullsafe。当${user}${user.address}解析为null时,它将跳过所有内容并且不显示任何内容。在scriptlet中,您会在嵌套调用中获得 NPE,或者null在最后一次调用中获得 NPE。

Then there is the unified EL, denoted by the #{} syntax. It's (as far) only used in combination with JavaServer Faces (JSF). It is able do to a call a Javabean setter on the last property. E.g.

<h:inputText name="foo" value="#{bean.foo}">

will behind the scenes roughly do like follows

pageContext.findAttribute("bean").setFoo(request.getParameter("foo"));

It's by the way not a view technology. JSP itself is already the view technology at its own. JSTL is just a taglib. EL is just part of the JSP spec. The other view technology provided by Java EE is Facelets which is XHTML based and provides much more seamless integration for JSF than JSP does.

于 2010-02-25T22:55:40.713 回答