EL函数(字符串超过指定的长度,则超过的内容以省略号代替)

1、EL函数类:ELUtil.java

package com.servlet.util;

public class ELUtilt {
	public static String substring(String source, Integer len){
		if(source.length() > 10){
			source = source.substring(0, 10) + "...";
		}
		return source;
	}
}


2、tld文件,放到/WEB-INF目录下(该tld文件在tomcat的\webapps\examples\WEB-INF\jsp2目录下有模板:jsp2-example-taglib.tld)



    A tag library exercising SimpleTag handlers.
    1.0
    SimpleTagLibrary
    /mytag

     
        substring
        com.servlet.util.ELUtilt
        java.lang.String substring( java.lang.String, java.lang.Integer )
    

3、jsp页面测试

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="tag" uri="/mytag"%>




Insert title here


	${tag:substring("aaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqqqq", 10)} 

显示效果:



你可能感兴趣的:(Servlet)