JSP compilation error when using autoboxing
Error below when executing below JSP content in Tomcat 7.0.54
<%
Object one = new Long(1);
Long value = Boolean.TRUE ? (Long)one : -1l;
%>
Mistake:
javax.servlet.ServletException: java.lang.Error: Unresolved compilation problem:
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:348)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Any pointer to the cause of the problem would help me understand the problem better. The jsp seems to be compiled into a .class file, but at runtime I get this issue. Thanks in advance.
+3
source to share
3 answers
Object is -1l
not Long
primitive data Long
try this:
<%
Object one = new Long(1);
Long value = Boolean.TRUE ? (Long)one : new Long(-1);
%>
The above code works when you compile and run the code with JDK, it seems like there might be an error in tomcat that is trying to convert JSP to Java before compiling
+1
source to share