According to the Tomcat version used, the JSP engine provided by tomcat uses a specific default version of Java to compile and run JSP.
Tomcat 7 uses the 1.6 version
compilerSourceVM - What JDK version are the source files compatible
with? (Default value: 1.6)
compilerTargetVM - What JDK version are the generated files compatible
with? (Default value: 1.6)
Tomcat 8 uses the 1.7 version
compilerSourceVM - What JDK version are the source files compatible
with? (Default value: 1.7)
compilerTargetVM - What JDK version are the generated files compatible
with? (Default value: 1.7)
Tomcat 9 uses the 1.8 version
compilerSourceVM - What JDK version are the source files compatible
with? (Default value: 1.8)
compilerTargetVM - What JDK version are the generated files compatible
with? (Default value: 1.8)
Of course, you may change the versions used if the default values don't match to your requirements.
You can do that by modifying the init parameters of the
org.apache.jasper.servlet.JspServlet
servlet declared
in your global $CATALINA_BASE/conf/web.xml
.
For example the web.xml
of the tomcat 8 distribution defined the JspServlet in this way :
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
...
For example to specify the 1.8
version both as source and target for JSP files, you should change it in this way :
...
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<!-- added params -->
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.8</param-value>
</init-param>
<!-- end added params -->
<load-on-startup>3</load-on-startup>
</servlet>
...