Chris,
This is a tricky problem to solve and most likely won’t be solved anytime soon. You know what bean:define does, so you know why the code above works. You also understand why the scriptlet executes correctly at run time (Because the variable exists). The problem is that the JSP syntax parser has no idea what bean:define does. Consider that I could write a custom taglib called “blork” with a method called “florp”, so I would have:
<blork:florp id="colours">
</blork:florp>
Let’s also say that I copy-paste all the code from Struts bean:define tag and put it in my blork taglib, so it does the identical thing. How can the parser know, from the syntax alone, that blork is creating a page-scoped variable with the name “colours”? It can’t without running the code and analyzing the result.
Anyway, the reason I say the problem most likely won’t be solved is because using scriplets in JSP pages have always been considered “Bad practice” even though sometimes you need to. Now with the JSP 2.0 spec you can actually set a flag (off by default I think) that disallows scriplets completely in the JSP pages, negating problems like these. So it’s my belief that moving forward the spec will continue to diswade developers from using scriplets so this problem will become even more of an edge case.