2017-08-26 91 views
0

我想限制jsp中的文本長度。如何限制jsp中的文本長度?

<c:forEach var="result" items="${resultList }" varStatus="status" > 
li>${result.mkType }</li> 

</> 

讓說,我要限制的$ {} result.mkType的長度

回答

1

JSTL有一個名爲fn:length()

您可以使用它來限制一個字符串或列表的長度功能大小與if測試。

例如:

<c:forEach var="result" items="${resultList}" varStatus="status" > 

    // below you test if the string variable length is greater(gt) than 4 
    // If it is greater than 4, then the code below will show, else nothing. 

    <c:if test="${fn:length(result.mkType) gt 4}"> 
    <li> 
    ${result.mkType} 
    </li> 
    </c:if> 

</c:forEach>