Using <c:set> with beans and Maps
This flavor of <c:set> (with its two variations—with and without a body) works for only two things: bean properties and Map values. That’s it. You can’t use it to add things to lists or arrays. It’s simple—you give it the object (a bean or Map), the property/key name, and the value.
Setting a target property or value with <c:set>
With NO body

WITH a body

Note
The “target” must evaluate to the OBJECT! You don’t type in the String “id” name of the bean or Map attribute!
This is a huge gotcha. In the <c:set> tag, the “target” attribute in the tag seems like it should work just like “id” in the <jsp:useBean>. Even the “var” attribute in the other version of <c:set> takes a String literal that represents the name of the scoped attribute. BUT... it doesn’t work this way with “target”!
With the “target” attribute, you do NOT type in the String literal that represents the name under which the attribute was bound to the page, scope, etc. No, the “target” attribute needs a value that resolves to the REAL THING. That means an EL expression or a scripting expression (<%= %>), or something we haven’t seen yet: <jsp:attribute>.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access