效果示例:
jsp頁面代碼:
使用JSTL的fn:length()函數:
<a class="font12gray" target="_blank" href="" class="font12gray" target="_blank">
<c:if test='${fn:length(sOnline.articleTitle)>18}'>${fn:substring(sOnline.articleTitle,0,18)}...</c:if>
<c:if test='${fn:length(sOnline.articleTitle)<=18}'>${sOnline.articleTitle}</c:if>
</a>
fn:length 設定標題顯示的字數,如果字數超過18個則顯示前18個字和...,如果不足18個字,則直接把所有字都顯示出來