Customize jstl function labels

Source: Internet
Author: User
Tags tld

Customize jstl function labels
Write a public class UtilFunction {public UtilFunction () {}/ *** @ param start 0, start intercept * @ param 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) {// 4 System after 3 mobile phone numbers. out. pri Ntln (UtilFunction. subString (3, 7, "15216888619", "*****") ;}2. Define a. tld file under 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 to obtain 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-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 is request. setBean () request bound to $ {userinfo. sMobile} remove $ {} If fn function is used, directly use userinfo. sMobile

Related Article

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.