开发者

Unable to find a value for "length" in object of class "java.lang.String" using operator "."

开发者 https://www.devze.com 2023-01-11 21:14 出处:网络
Why does this JSTL expression not seem to be able to use the length method of the String class: &l开发者_JS百科t;c:when test=\"${displayName != null && displayName.length > 0 }\">

Why does this JSTL expression not seem to be able to use the length method of the String class:

    &l开发者_JS百科t;c:when test="${displayName != null && displayName.length > 0 }">
        <p><c:out value="${displayName}"/></p>
    </c:when>

It produces this exception:

java.lang.RuntimeException: javax.servlet.ServletException: 
javax.servlet.jsp.el.ELException: Unable to find a value for "length" in object 
of class "java.lang.String" using operator "."

I have included the following tag libraries at the top of the JSP:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>


You can access only getters (getSomething) like this. To find string size, try fn:length(displayName). Naturally, fn namespace should be imported:

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Also, you can replace this all with empty check: ${not empty displayName}


See if this helps.

You'll have to add

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
0

精彩评论

暂无评论...
验证码 换一张
取 消