我在JSTL文件中有下一个代码:
<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是F,但我收到了下一个错误:
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}&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>
在使用Apache Tomcat 6.0的本地服务器中,此代码没有出现任何问题。
在我的应用服务器上使用tomcat 5.5会出现上述错误。
有谁知道为什么会这样?
如果我使用 == 而不是 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}&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>
答案 0 :(得分:1)
异常表示application.lodging
是数字,而不是字符串。是对的吗?在这种情况下,您可能需要先将“F”,“H”,“B”字符串转换为数字(是否要比较字符?)
答案 1 :(得分:0)
您是否尝试对字符串进行简单比较,如suggested in this answer?
<c:when test="${application.lodging=='F'}"><bean:message key="courseapplication.lodgingF"/></c:when>
可能适用于两种环境......