• 自定义EL函数:小写转大写


    1,定义java静态方法,FunctionDemo,有小写转大写的功能

    package com.itheima.domain;
    
    public class FunctionDemo {
    	public static String toUpperCase(String string){
    		return string.toUpperCase();
    	}
    }
    

     2,编辑xml文件,扩展名为tld

    需要指定类的详细名称,带包名,方法的详细信息,返回值+方法名+参数,和访问路径uri,在页面中导入这个uri才能使用,前缀

    <?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>itheima</short-name>
      <uri>http://www.heima.com/jsp/myfun</uri>
    
      <function>
        <description>
          toUpperCase
        </description>
        <name>toUpperCase</name>
        <function-class>com.itheima.domain.FunctionDemo</function-class>
        <function-signature>java.lang.String toUpperCase(java.lang.String)</function-signature>
        <example>
          <itheima:toUpperCase("aavvavb")>
        </example>
      </function>
    </taglib>
    

     3在页面中使用,需要用taglib标签,指定uri和前缀

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
     <%@taglib uri="http://www.heima.com/jsp/myfun" prefix="itheima" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
     ${itheima:toUpperCase("adsafjka") }
    </body>
    </html>
    
  • 相关阅读:
    应用服务器性能优化总结
    Web性能优化:图片优化
    图片优化
    浏览器端的九种缓存机制介绍
    MySQL 与 MongoDB的操作对比
    js类型判别大合集
    节流函数和防抖函数的注意事项
    前端和后端交互的方式
    js中关于假值和空数组的总结
    LeetCode 367. 有效的完全平方数
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4719226.html
Copyright © 2020-2023  润新知