【问题标题】:JSP 2.2 EL it keyword in Jersey Viewable - where is it documented?Jersey Viewable 中的 JSP 2.2 EL it 关键字 - 它在哪里记录?
【发布时间】:2013-06-12 23:03:56
【问题描述】:

我发现如果我有一个 Viewable (jersey) 将模型传递给 JSP,那么访问它的方法是在映射键前面加上 it

例如

index.jsp

<html>
<body>
<h2>Hello World ${it.foo}!</h2>
</body>
</html>

JAX-RS 资源方法:

@GET
@Path("index")
public Viewable index(@Context HttpServletRequest request) {
    System.out.println("/INDEX called");
  HashMap<String, String> model = new HashMap<String, String>();
  model.put("foo","bar");
  return new Viewable("/index.jsp", model);
}

我是基于这个资源:http://blog.usul.org/using-jsp-in-a-jersey-jax-rs-restful-application/

但我想知道,it 是什么,它来自哪里,是泽西岛特有的吗?如果是这样,它在哪里记录(很难搜索“它”,因为谷歌倾向于将其从搜索中删除,没有双关语)

在 Java EE 文档中找不到任何提及它的内容。

【问题讨论】:

    标签: java jsp jersey el


    【解决方案1】:

    this documentation 的第 17.4 节中。它指出:

    Jersey 会将模型实例分配给名为“it”的属性。所以 在隐式示例的情况下,可以引用 foo 来自 JSP 模板的 Foo 资源的属性如下:

    &lt;h1&gt;${it.foo}&lt;/h1&gt;

    所以it 只是 Jersey 特定的模型属性。因为它是一个模型属性,在视图被渲染之前的某个时刻,它被添加到请求属性中。然后可以使用 EL 访问器 ${} 访问它。如果它被命名为jerseyGuy,您将使用${jerseyGuy} 访问它。

    EL 解析${...} 表达式,使用PageContext#findAttribute() 将属性名称解析为页面、请求、会话或应用程序上下文中的某个属性。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2013-02-21
    • 2013-05-25
    • 1970-01-01
    • 2019-12-23
    • 2020-05-21
    • 2018-03-27
    相关资源
    最近更新 更多