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]的错误原因和解决办法

错误代码:

checked="checked" />男 checked="checked" />女

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: 鐢?
39: 濂?
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可以成功运行。

javax.el.ELException: Cannot convert [男] of type [class java.lang.String] to [class java.lang.Long]_第1张图片在JSP EL表达式内可以使用的数据类型有:整型数(long),浮点数(double),字符串,常量true、false,还有null。对于java的char类型,EL表达式将会自动转换为整型数(long)。如果char类型中的值为中文,那么就会转型失败而报错。

解决办法:

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

你可能感兴趣的:(javax.el.ELException: Cannot convert [男] of type [class java.lang.String] to [class java.lang.Long])