Setp1:编写FirstFunction.tld文件
- <?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.1</tlib-version>
- <short-name>sl</short-name> <!-- quote this name in pages,sl is show list-->
- <function>
- <name>displayAll</name> <!-- This is method's name -->
- <function-class>org.eagle.testFunction.Display </function-class> <!-- This is handle Class -->
- <function-signature>void displayAll(java.util.List)</function-signature> <!-- The definition of class -->
- </function>
- </taglib>
step2:编写处理类org.eagle.testFunction.Display .java
- /**
- *
- */
- package org.eagle.testFunction;
- import java.util.List;
- /**
- * @author zhenhuaZhu
- *
- */
- public class Display {
- public static void displayAll(List list){
- for (Object obj: list) {
- System.out.println(obj);
- }
- }
- }
step3:页面调用
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%@ taglib prefix="ft" uri="/WEB-INF/firstTag.tld"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <%
- List l = new LinkedList();
- l.add("hello");
- l.add("java");
- l.add("world");
- request.setAttribute("l", l);
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- <ft:print parameter2="${l}"/>
- </body>
- </html>