JSP 2.2 EL it keyword in Jersey Viewable - where is it documented?

爱⌒轻易说出口 提交于 2020-01-05 08:17:15

问题


I've found out that if I have a Viewable (jersey) passing a model to a JSP, then the way to access it is by prefixing the map key with it

e.g.

index.jsp

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

The JAX-RS resource method:

@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);
}

I was basing on this resource: http://blog.usul.org/using-jsp-in-a-jersey-jax-rs-restful-application/

but I was wondering, what is it and where does it come from, is it specific to Jersey? if so where is it documented (it's hard to search for "it" as google tends to removes it from the search, no pun intended)

Could not find any mention of it in the Java EE documentation.


回答1:


In sections 17.4 of this documentation. It states:

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>

So it is just a Jersey specific model attribute. Since it's a model attribute, at some point before the view gets rendered, it gets added to request attributes. It can then be accessed with the EL accessor ${}. If it was named jerseyGuy, you would access it as ${jerseyGuy}.

EL, which resolves ${...} expressions, uses PageContext#findAttribute() to resolve the attribute name to some attribute in the page, request, session, or application context.



来源:https://stackoverflow.com/questions/17076829/jsp-2-2-el-it-keyword-in-jersey-viewable-where-is-it-documented

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!