Use Scoped Variables in JSP Templates and Tag files - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 11. There's an updated version available that covers our most recent release.

04-07-2016

Use Scoped Variables in JSP Templates and Tag files

The Unified Expression Language 3.0 adds support for referencing static fields and methods. "Supporting this feature in JSPs required changing the javax.servlet.jsp.el.ScopedAttributeELResolverimplementation so that it also checked identifiers to see if they were names of imported classes or fields" [1]

This has the effect that all unscoped variables which are undefined have a large performance drain. Especially tag files tend to have non-required attributes which will have this problem. The solution is to simply scope the variable in tag files and JSPs. Generally for variables coming from components this means adding requestScope. For tag file attributes you should add pageScope.

${undefinedVariable}

becomes:

${requestScope.undefinedVariable}

or

${pageScope.undefinedVariable}

We recommend you always properly scope your variables to avoid this problem. Strictly speaking it may suffice to only treat your most used JSPs and tag files this way. However if you always scope your variables you can immediately dismiss this as an issue in case you do have performance problems.

References

[1] https://tomcat.apache.org/migration-8.html

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?