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
Cheran
source
to share
3 answers
Try
<%
Object one = new Long(1);
Long value = (Boolean.TRUE ? (Long)one : -1l);
%>
+1
Roman C
source
to share
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
Alireza fattahi
source
to share
Object one = (long) 1;
Long value = Boolean.TRUE ? (Long)one : -1l;
Try using the previous code instead of yours
In java the following is: "Optional box for Long"
Object one = new Long(1);
0
Afsun Khammadli
source
to share