tags:

views:

906

answers:

2

I have the next code in a JSTL file:

<c:choose>
    <c:when test="${application.lodging eq 'F'}"><bean:message key="courseapplication.lodgingF"/></c:when>
    <c:when test="${application.lodging eq 'H'}"><bean:message key="courseapplication.lodgingH"/></c:when>
    <c:when test="${application.lodging eq 'B'}"><bean:message key="courseapplication.lodgingB"/></c:when>
</c:choose>

$application.lodging is F but i am getting the next error:

SEVERE: ServletException in '/administration/jsp/applications.jsp': An exception occured trying to convert String "F" to type "java.lang.Long"
org.apache.jasper.JasperException: Exception in JSP: /administration/jsp/applications.jsp:20

17: <h2><a href="application.do?id=${application.id}&amp;type=S">${application.name}</a></h2>
18: <h3>
19: <c:choose>
20:     <c:when test="${application.lodging eq 'F'}"><bean:message key="courseapplication.lodgingF"/></c:when>
21:     <c:when test="${application.lodging eq 'H'}"><bean:message key="courseapplication.lodgingH"/></c:when>
22:     <c:when test="${application.lodging eq 'B'}"><bean:message key="courseapplication.lodgingB"/></c:when>
23: </c:choose>

In my local server with Apache Tomcat 6.0, this code was not giving any problem.

In my apps server with tomcat 5.5 is giving the above error.

Does anyone knows why this can be?

Same happens if I use == instead of eq

SEVERE: ServletException in '/administration/jsp/applications.jsp': An exception occured trying to convert String "F" to type "java.lang.Long"
org.apache.jasper.JasperException: Exception in JSP: /administration/jsp/applications.jsp:20

17: <h2><a href="application.do?id=${application.id}&amp;type=S">${application.name}</a></h2>
18: <h3>
19: <c:choose>
20:     <c:when test="${application.lodging=='F'}"><bean:message key="courseapplication.lodgingF"/></c:when>
21:     <c:when test="${application.lodging=='H'}"><bean:message key="courseapplication.lodgingH"/></c:when>
22:     <c:when test="${application.lodging=='B'}"><bean:message key="courseapplication.lodgingB"/></c:when>
23: </c:choose>
A: 

Did you try to use a simple comparison against string, as suggested in this answer ?

<c:when test="${application.lodging=='F'}"><bean:message key="courseapplication.lodgingF"/></c:when>

might work in both environment...

VonC
+1  A: 

Exception indicates that that application.lodging is number, not string. Is that right? In such case, you might need to convert your 'F', 'H', 'B' strings to numbers first (do you want to compare characters?)

Peter Štibraný