在应用程序类'org.apache.el.lang.ELSupport.coerceToNumber:364

时间:2016-08-22 03:47:49

标签: java jsp java-ee el websphere-liberty

我收到此JSP引发的错误。 这适用于WebSphere 7.0,但在Liberty profile 8.5

中失败
    [ERROR   ] SRVE0777E: Exception thrown by application class 'org.apache.el.lang.ELSupport.coerceToNumber:364'
javax.el.ELException: Cannot convert 34|5:00 PM  of type class java.lang.String to class java.lang.Long
    at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:364)
    at [internal classes]
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_40(_myCalAreaRole.java:4286)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_otherwise_1(_myCalAreaRole.java:4370)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_choose_1(_myCalAreaRole.java:4413)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_forEach_11(_myCalAreaRole.java:4457)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_36(_myCalAreaRole.java:5502)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_14(_myCalAreaRole.java:7663)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_13(_myCalAreaRole.java:7763)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_11(_myCalAreaRole.java:7814)
    at com.ibm._jsp._myCalAreaRole._jspx_meth_c_if_8(_myCalAreaRole.java:7864)
    at com.ibm._jsp._myCalAreaRole._jspService(_myCalAreaRole.java:374)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:101)
    at [internal classes]
    at com.ibm._jsp._myCalArea._jspx_meth_c_if_5(_myCalArea.java:1695)
    at com.ibm._jsp._myCalArea._jspx_meth_c_if_3(_myCalArea.java:1823)
    at com.ibm._jsp._myCalArea._jspService(_myCalArea.java:203)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:101)
    at [internal classes]
    at edu.mayo.MainController.goTo(MainController.java:1751)
    at edu.mayo.MainController.doGet(MainController.java:515)
    at edu.mayo.MainController.doPost(MainController.java:1745)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
    at [internal classes]

我能够看到完成这一切的JSP部分。

<select name="StartTime${Cnt}">
          <c:forEach var="Periods" items="${Periods}">
                <c:set var="period_id" value="${Periods.period_id}"/>
                <c:if test='${period_id == RolePerson.starttime}'>
                <option value="${period_id}|${Periods.period_text}" selected>${Periods.period_text}</option>
                </c:if>       
           <c:if test='${period_id != RolePerson.starttime}'>
           <option value="${period_id}|${Periods.period_text}">${Periods.period_text}</option>
            </c:if>       
       </c:forEach>
       </select>

HTML输出看起来像..

<select name="StartTime2">
<option value="0|12:01 AM">12:01 AM</option>
<option value="1|12:30 AM">12:30 AM</option>
…
<option value="34|5:00 PM ">5:00 PM </option>

似乎34 | 5:00 PM被select选项视为一个数字,所以它试图解析它。

我还在EL javax code online

中找到了强制方法..
protected final static Number coerceToNumber(final String val,
        final Class type) {
    if (Long.TYPE == type || Long.class.equals(type)) {
        return Long.valueOf(val);
    }
    if (Integer.TYPE == type || Integer.class.equals(type)) {
        return Integer.valueOf(val);
    }
    if (Double.TYPE == type || Double.class.equals(type)) {
        return Double.valueOf(val);
    }
    if (BigInteger.class.equals(type)) {
        return new BigInteger(val);
    }
    if (BigDecimal.class.equals(type)) {
        return new BigDecimal(val);
    }
    if (Byte.TYPE == type || Byte.class.equals(type)) {
        return Byte.valueOf(val);
    }
    if (Short.TYPE == type || Short.class.equals(type)) {
        return Short.valueOf(val);
    }
    if (Float.TYPE == type || Float.class.equals(type)) {
        return Float.valueOf(val);
    }
    throw new IllegalArgumentException(MessageFactory.get("error.convert",
            val, String.class, type));
}

我看到select可以有String值,但是看起来这个以34开头的值被认为是一个int / long或者数字,所以它被解析为数字和解析的一半,因为它是一个String类型。

不确定但有没有办法可以强制让编译器知道值类型是一个字符串所以它不会尝试自动检测......

由于 Dhiren

0 个答案:

没有答案