aspose file tools*
The moose likes JSP and the fly likes Make your JSp compatible with Java 7 standards. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Make your JSp compatible with Java 7 standards." Watch "Make your JSp compatible with Java 7 standards." New topic
Author

Make your JSp compatible with Java 7 standards.

Anshum Kocher
Greenhorn

Joined: Nov 26, 2012
Posts: 5
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

Joined: Jan 28, 2012
Posts: 7

As specified in the error - you cannot use switch on strings before Java 7. Change the compliance level or change the code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42612
    
  65
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.


Ping & DNS - my free Android networking tools app
Anshum Kocher
Greenhorn

Joined: Nov 26, 2012
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61654
    
  67

Step 1: Use JSTL instead of Java scriptlets in the JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make your JSp compatible with Java 7 standards.