O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Key points and gotchas with <c:set>

Yes, <c:set> is easy to use, but there are a few deal-breakers you have to remember...

Note

  • You can never have BOTH the “var” and “target” attributes in a <c:set>.

  • “Scope” is optional, but if you don’t use it the default is page scope.

  • If the “value” is null, the attribute named by “var” will be removed!

  • If the attribute named by “var” does not exist, it’ll be created, but only if “value” is not null.

  • If the “target” expression is null, the Container throws an exception.

  • The “target” is for putting in an expression that resolves to the Real Object. If you put in a String literal that represents the “id” name of the bean or Map, it won’t work. In other words, “target” is not for the attribute name of the bean or Map—it’s for the actual attribute object.

  • If the “target” expression is not a Map or a bean, the Container throws an exception.

  • If the “target” expression is a bean, but the bean does not have a property that matches “property”, the Container throws an exception. Remember that the EL expression ${bean.notAProperty} will also throw an exception.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required