Jsp页面 (jstl标签)判断字符串大于固定长度显示省略号

<一>需要导入的Jar包依赖

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

</dependency>

<二>需要导入的jsp页面标签头

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

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

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

<三>具体实现代码如下

  方式一:(如果>10放在el表达式之外test双引号以内,jsp页面什么也不显示)

    <c:if test="${fn:length(u.attachs) > 10 }">

        ${fn:substring(u.attachs,0,10)}...

    </c:if>

    <c:if test="${fn:length(u.attachs)<= 10 }">

        ${u.attachs}

    </c:if>

  方式二:(通方式一一样,判断的符号和数字不能放在test双引号内部,只能放在el表达式内

    <c:choose>

      <c:when test="${fn:length(u.attachs) > 10 }">

        ${fn:substring(u.attachs,0,10)}...

      </c:when>

      <c:otherwise>

        ${u.attachs}

      </c:otherwise>

    </c:choose>

猜你喜欢

转载自blog.csdn.net/sheinenggaosuwo/article/details/84970582
今日推荐