java - JSP 2.2 EL it 关键字在 Jersey Viewable - 它记录在哪里?

标签 java jsp jersey el

我发现如果我有一个 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/

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

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

最佳答案

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

Jersey will assign the model instance to the attribute named "it". So in the case of the implicit example it is possible to referece the foo property on the Foo resource from the JSP template as follows:

<h1>${it.foo}</h1>

所以 it只是 Jersey 特定的模型属性。由于它是一个模型属性,因此在呈现 View 之前的某个时刻,它会被添加到请求属性中。然后可以使用 EL 访问器访问它 ${} .如果它被命名为 jerseyGuy ,您将以 ${jerseyGuy} 的形式访问它.

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

关于java - JSP 2.2 EL it 关键字在 Jersey Viewable - 它记录在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17076829/

相关文章:

MySQL 根据变量更新查询

java - 带有 JSON 的 Jersey RESTful 服务

java - JPA createNativeQuery 未映射到实体类

java - 为什么我使用 fmt :message into a JSP page? 时遇到国际化\本地化问题

javascript - 在非 Angular jsp中包含带 Angular jsp时出错

java - Jersey Response.seeOther() 未给出 HTTP 303 状态代码

jaxb - Jersey + Moxy + JAXB - 如何在没有注释的情况下编码 XML

java - 有没有办法在初始化枚举时传递变量而不是在java中传递实际值?

java - Spring JDBC 中使用 BeanPropertySqlParameterSource 的 SQLSyntaxErrorException

java - 在java上备份mysql数据库