Sling permits rendering JSP with scriptlets. By default, the JSP compiler targets Java 6 compatibility. When running on newer JVM versions and wanting to use features like diamond operators (Java 7) or lambdas and streams (Java 8), you must configure the JSP Scripts Handler accordingly.
The Problem
Without proper configuration, compilation errors appear when using newer Java syntax:
1
2
org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
java.io.IOException: unexpected tag: 18
Solution
Method 1: Web Console Configuration
Navigate to:
1
/system/console/configMgr/org.apache.sling.scripting.jsp.JspScriptEngineFactory
Set both Target Version and Source Version fields to your desired Java version (e.g., 1.8).
Method 2: Configuration File
Create a file named org.apache.sling.scripting.jsp.JspScriptEngineFactory.config with:
1
2
jasper.compilerTargetVM="1.8"
jasper.compilerSourceVM="1.8"
After applying either configuration, JSP scriptlets will support modern Java syntax features.