自定义页面方法tld标签

一、把tld文件放在WebContent目录下或其子目录下。这样的话,web.xml不用配置其位置即可。tomcat直接读取webcontent下的tld文件。

二、TldTest类:

 1 package tlds;
 2  
 3 /**
 4  * 自定义标签测试类
 5  * @author Administrator
 6  */
 7 public class TldTest {
 8     public static String sayHelloToName(String name) {
 9         return "hello!"+name;
10     }
11 }

三、fns.tld

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2  
 3 <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
 4   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
 6   version="2.0">
 7     
 8   <description>JSTL 1.1 functions library</description>
 9   <display-name>JSTL functions sys</display-name>
10   <tlib-version>1.1</tlib-version>
11   <short-name>fns</short-name>
12   <uri>http://java.sun.com/jsp/jstl/functionss</uri>
13  
14   <function>
15     <description>打招呼</description>
16     <name>sayHelloToName</name>
17     <function-class>tlds.TldTest</function-class>
18     <function-signature>java.lang.String sayHelloToName(java.lang.String)</function-signature>
19     <example>${fns:sayHelloToName()}</example>
20   </function>
21  
22 </taglib>

四、index.jsp

 1 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
 2 <%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
 3 <html>
 4  
 5 <head>
 6     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7     <title>自定义方法测试</title>
 8 </head>
 9  
10 <body>
11     ${fns:sayHelloToName('zhengxiangwen')}
12 </body>
13  
14 </html>

五、收藏了几个适合学习的网址,从简单的配置,到具体的使用。
http://www.cnblogs.com/liupeizhi/category/281132.html

http://www.cnblogs.com/edwardlauxh/default.html?page=9

以上都写了几个系列文章,可以根据以上的文章进行锻炼。

原文:https://blog.csdn.net/zhengxiangwen/article/details/40652019

posted on 2019-05-06 10:23  江清澜静  阅读(195)  评论(0编辑  收藏  举报

导航