Wednesday, March 21, 2007

JSTL and JSP Expression Language used in JSP 2.0

The release of the JSP 2.0 and servlet 2.4 specification has changed the way expressions are used within JSP pages.
From now on you can use expressions throughout the whole JSP page.
There appeared to be some limitations though, when mixing expressions with tags, you can only use expressions within tag attribute values.
So name is ${}. is perfectly legal, as well as href="${link.url}" />But ${attrName} is not.

When trying to figure this out, I stumbled over several issues before I got the desired output. First you must declare your application as a 2.4 webapp using the following declaration:

<web-app xmlns=""
xsi:schemaLocation=" web-app_2_4.xsd"
version="2.4" />

When using the JSTL taglibrary, you must be aware that the taglib url is different, jsp is added prior to jstl within the URL.

For 2.3 webapps you should use taglib <%@taglib uri="" prefix="c"%> while for 2.4 webapps you use <%@taglib uri="" prefix="c" %> />


patman said...

Hi Marcel,

The root element should be web-app, not webapp ;-)

SpiderMars said...

Thanks patman, I'll correct it!