Search code examples
javajsptomcat7

String value in Java 1.7 switch statement throwing an error?


Any one knows what is this error saying:

An error occurred at line: 388 in the jsp file: /historical_weather.jsp

Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted

I am using Java 7.0. Still I get this error. Thanks


Solution

  • This might be happning because you are using Tomcat-7 or below.

    Tomcat-7 uses source level as 1.6 to compile JSPs Ref. To resolve this problem you can to use Tomcat-8 since Tomcat-8 uses source level as 1.7 for JSPs.

    Another solution, if you want to use Tomcat-7, is to change source level as 1.7 in Tomcat-7, for that you have to add below entries for the servlet jsp in [TOMCAT_HOME]/conf/web.xml :

    <init-param>
        <param-name>compilerSourceVM</param-name>
        <param-value>1.7</param-value>
    </init-param>
    <init-param>
        <param-name>compilerTargetVM</param-name>
        <param-value>1.7</param-value>
    </init-param>
    

    For more detail : how-to-set-tomcat-7-source-level-to.html

    Note: I am talking about only JSPs for whom Tomcat generates java code and compile them. For other Java classes source level would be same as your JDK version.