JSP:jstl核心CONDITIONS与java.lang.Byte []

时间:2016-10-26 06:54:52

标签: java jsp jstl el

我在我的JSP中使用部署在WebLogic Server版本:12.1.2.0.0中的spring MVC应用程序中有这段代码。我正在使用 jstl-1.2

2-> [${item.companyLogo}]
3-> [${empty item.companyLogo}]
4-> [${item.companyLogo eq null}]
<c:choose>
<c:when test="${empty item.companyLogo} ">
IS EMPTY
<img src="${contextPath}/images/devices-logo.gif"  />
</c:when>
<c:otherwise>
NOT EMPTY
</c:otherwise>
</c:choose>

也尝试了

<c:when test="${empty item.companyLogo == true} ">

但是在屏幕上我看到了这些:

2-> [] 
3-> [true] 
4-> [true] 

NOT EMPTY  

如果我尝试使用${item.companyLogo.length}检查长度 我收到了这个错误:

]] Root cause of ServletException.
java.lang.NumberFormatException: For input string: "length"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:492)
        at java.lang.Integer.parseInt(Integer.java:527)
        at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:378)
        at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:198)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
        at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
        at weblogic.servlet.jsp.ELHelper.evaluate(ELHelper.java:32)
        at jsp_servlet._web_45_inf._jsp._result.__productcategoryresult._jspService(__productcategoryresult.java:330)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
        at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:478)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:367)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
        at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:573)
        at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:480)
        at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:347)
        at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:204)
        at jsp_servlet._web_45_inf._jsp._template.__template._jsp__tag10(__template.java:659)

这是属性companyLogo

的类型
Byte[] companyLogo;

1 个答案:

答案 0 :(得分:0)

改为使用JSTL函数length

  • 在页面的开头也导入函数taglib:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    
  • 然后得到长度:

    ${fn:length(item.companyLogo)}