This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See jsp fragments, or jsp at general actually. I'm trying to design a system in which pages can be build with various building blocks. Ideally each of these blocks act completly independent of one another. However as I understand JSP fragments, there is no way to prevent different blocks (fragments) from interfering with each other if they decide to use the same variables names. Can anyone tell me if my assumption is correct? If so, is there another solution than just make sure that the names are different?
Yes, all "blocks" on a JSP page will share the same page context and therefore the same scopes. You can always try the time-tested approach of name-spacing. E.g. all scoped variables created by logical construct "fred" are named fred.this or fred.that or fred.theOtherThing.
This assumes that you are talking about JSP 2.0 and scoped variables accessed by the EL. If you are still using old-fashioned scriptlets.... well, don't.
I figured as much, but I hoped that I had missed something somehow. The system I'm designing people may put more blocks on one page, even if that means that the very same block is being used more than just once on the very same page. In such a case using namespacing would not work anymore. Also other people may create new blocks to be used on a page, I really wanted to find something which didn't need to force extra rules upon these people, because they will probably be broken anyway. Thanks for your help, it still helped a lot!