简体   繁体   English

Java 1.7中的字符串值switch语句抛出错误?

[英]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 在jsp文件中的行:388处发生错误:/hisicalical_weather.jsp

Cannot switch on a value of type String for source level below 1.7. 如果源级别低于1.7,则无法为String类型的值打开。 Only convertible int values or enum variables are permitted 只允许使用可转换的int值或枚举变量

I am using Java 7.0 . 我使用的是Java 7.0 Still I get this error. 我仍然得到这个错误。 Thanks 谢谢

This might be happning because you are using Tomcat-7 or below. 这可能很高兴,因为您使用的是Tomcat-7或更低版​​本。

Tomcat-7 uses source level as 1.6 to compile JSPs Ref . Tomcat-7使用源级别1.6来编译JSP Ref To resolve this problem you can to use Tomcat-8 since Tomcat-8 uses source level as 1.7 for JSPs. 要解决此问题,您可以使用Tomcat-8,因为Tomcat-8将源级别用作JSP的1.7。

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 : 如果你想使用Tomcat-7,另一个解决方案是在Tomcat-7中将源级别更改为1.7,因为你必须在[TOMCAT_HOME] /conf/web.xml中为servlet jsp添加以下条目:

<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 有关更多详细信息: 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. 注意:我只讨论Tomcat为其生成Java代码并编译它们的JSP。 For other Java classes source level would be same as your JDK version. 对于其他Java类,源级别与JDK版本相同。

检查项目属性(无论安装的JDK如何,您始终可以在每个IDE上设置较低的编译级别)或Maven构建配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM