• eclipse新建自定义EL函数


    ===============================================================================================================================

    step1:新建一个java类

    这个类有一点需要注意,方法必须是静态的. 这个也好理解,EL调用的函数,可以算是一个工具类,没有必要先实例化再调用. 最理想的方法就是整成静态方法,直接通过类来调用就可以了.

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    package net.thecatcher.ELdemo;

    public class ELDemo1 {

    public static String sayHello(String name){

    return "hello "+ name;

           }

    }

    ===============================================================================================================================

    step2: 需要编辑的tld文件

    我用的eclipse,查到的方法是这样来建,但是,貌似不太好使. 我都是直接复制下面这段代码,然后再修改...

    New ----> XML ----> XML File ----> 输入test.tld
    ----> Create XML file from a DTD file ----> Select XML Catalog entry
    ----> -//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN 
    ----> finish

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    <?xmlversion="1.0"encoding="UTF-8"?>

    <taglib version="2.0" 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">

    <tlib-version>1.0</tlib-version>

    <short-name>myfn</short-name>

    <uri>http://www.thecatcher/myfn</uri>

    <function>

    <name>sayHi</name>

    <function-class>net.thecatcher.ELdemo.ELDemo1</function-class>

    <function-signature>java.lang.String sayHello(java.lang.String)</function-signature>

    </function>

    </taglib>

    ===============================================================================================================================

    step3: jsp文件中通过taglib引用

    -------------------------------------------------------------------------------------------------------------------------------

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

    pageEncoding="UTF-8"%>

    <%@ taglib uri="http://www.thecatcher/myfn" prefix="myfn" %>

    <!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>

    ${ myfn:sayHi("meimei")}

    </body>

    </html>

  • 相关阅读:
    hbase-15-如何查看HFile
    Hbase-14-MemStore Flush的触发时机
    Hbase-13-MemStore
    【c++】C++中erase的用法
    Redis五种数据结构(转载)
    redis的三种集群方式 (转载)
    hbase和hive的差别是什么,各自适用在什么场景中?(转载)
    vue 数据已经更新了但是页面未更新
    uni-app配置跨域
    覆盖 web-view (uni-app)
  • 原文地址:https://www.cnblogs.com/thecatcher/p/5751409.html
Copyright © 2020-2023  润新知