Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make your JSp compatible with Java 7 standards.

 
Anshum Kocher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this error, how could i resolve it


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 12 in the jsp file: /disp.jsp
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted
9: <body>
10: <%
11: String s=(String)request.getAttribute("null");
12: switch(s){
13: case "true":
14: out.println("Cool new session");
15: break;

 
Benny Zlo
Greenhorn
Posts: 7
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As specified in the error - you cannot use switch on strings before Java 7. Change the compliance level or change the code.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With an If/else statement. Of course, Java code should not be part of a JSP, so if want to keep logic in a JSP you should use the corresponding JSTL tags instead.
 
Anshum Kocher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would i Change the compliance level of the code , currently i am using default settings in eclipse [eclipse newbie alert]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64847
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Step 1: Use JSTL instead of Java scriptlets in the JSP.
 
Stefan Evans
Bartender
Posts: 1721
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default Tomcat JSP compiler will compile to Java 1.6. As such you can't use Strings in a switch statement which is a Java 7 feature.
Check out the Tomcat documentation for how to specify which compiler is used for JSP pages.
Of particular interest should be the parameters for

- compiler
- compilerTargetVM

Setting compilerTargetVM to 1.7 should allow the page to compile as is.
However the better solution as already mentioned is not to use scriptlets in your JSP page.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic