简体   繁体   中英

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

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

eg

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM