javax.el.ELException: Cannot convert [男] of type [class java.lang.String] to [class java.lang.Long]

javax.el.ELException: Cannot convert [男] of type [class java.lang.String] to [class java.lang.Long]的错误原因和解决办法

错误代码:

<div class="form-group">
            <label>性别:</label>
            <input type="radio" name="sex" value="男"  <c:if test="${contact.sex=='男'}">checked="checked"</c:if> />男
            <input type="radio" name="sex" value="女"  <c:if test="${contact.sex=='女'}">checked="checked"</c:if> />女
        </div>

log报错:

18-Sep-2019 22:30:48.549 严重 [http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [FindContactServlet] in context with path [/LoginSys_war_exploded] threw exception [An exception occurred processing [/admin/update.jsp] at line [38]

35:
36:


37:
38: <input type=“radio” name=“sex” value=“鐢?” ${contact.sex==‘鐢?’ ?‘checked=“checked”’:’’} />鐢?
39: <input type=“radio” name=“sex” value=“濂?” ${contact.sex==‘濂?’ ?‘checked=“checked”’:’’} />濂?
40:

41:

Stacktrace:] with root cause
javax.el.ELException: Cannot convert [男] of type [class java.lang.String] to [class java.lang.Long]
at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:405)
at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:384)
at org.apache.el.lang.ELSupport.equals(ELSupport.java:178)
at org.apache.el.parser.AstEqual.getValue(AstEqual.java:39)
at org.apache.el.parser.AstChoice.getValue(AstChoice.java:44)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:702)
at org.apache.jsp.admin.update_jsp._jspService(update_jsp.java:169)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

报错原因:

多次检查代码并没有发现错误 ,然后发现将javabean类中的sex属性类型char改为String可以成功运行。

将sex属性类型char改为String在JSP EL表达式内可以使用的数据类型有:整型数(long),浮点数(double),字符串,常量true、false,还有null。对于java的char类型,EL表达式将会自动转换为整型数(long)。如果char类型中的值为中文,那么就会转型失败而报错。

解决办法:

所以将sex属性类型改为EL表达式支持的字符串(String)可以很好的解决这个问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值