Custom Jstl function Label

Source: Internet
Author: User

  1. Write a tool class

    public class Utilfunction {

    Public Utilfunction () {

    }

    /**
    * @param start 0,start intercept
    * @param end end, intercept
    * @param info
    * @param t fill
    * @return
    */
    public static String subString (int start,int end,string info,string t) {
    String infostart=info.substring (0,start);
    String infoend=info.substring (end);
    return infostart+t+infoend;
    }

    Test
    public static void Main (string[] args) {
    Mobile phone number before 3 4
    System.out.println (Utilfunction.substring (3, 7, "15216888619", "* * * *"));
    }
    }

2. Define a. tld file below the Web-inf

<?xml version= "1.0" encoding= "UTF-8"?>

<taglib xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version= "2.0" >

<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://www.xx.com</uri>

<!--jstl Custom function Get province--
<function>
<name>subString</name>
<function-class>util. Utilfunction</function-class>
<function-signature>java.util.string subString (int, int,java.lang.string,java.lang.string) </ Function-signature>
</function>
</taglib>


3.web.xml definition

<jsp-config>
<taglib>
<taglib-uri>http://www.xx.com</taglib-uri>
<taglib-location>/WEB-INF/tld/utilFunction.tld</taglib-location>
</taglib>
</jsp-config>


4.jsp page reference

<%@ taglib uri= "http://java.sun.com/jsp/jstl/functions" prefix= "FN"%>
<%@ taglib prefix= "YH" uri= "http://www.xx.com"%>


${xx:substring (3, 7, Userinfo.smobile, "* * *")}


Note:

UserInfo for Request.setbean ()

Request binding is ${userinfo.smobile} if the FN function uses remove ${}, direct userinfo.smobile

Custom Jstl function Label

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.