自定义函数

 Setp1:编写FirstFunction.tld文件

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  3.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  5.   version="2.0">
  6.     
  7.   <tlib-version>1.1</tlib-version>
  8.   <short-name>sl</short-name> <!-- quote this name in pages,sl is show list-->
  9.   <function>
  10.     <name>displayAll</name>  <!-- This is method's name -->
  11.     <function-class>org.eagle.testFunction.Display </function-class> <!-- This is handle Class -->
  12.     <function-signature>void displayAll(java.util.List)</function-signature> <!-- The definition of class  -->
  13.   </function>
  14. </taglib>

 

step2:编写处理类org.eagle.testFunction.Display .java

 

  1. /**
  2.  * 
  3.  */
  4. package org.eagle.testFunction;
  5. import java.util.List;
  6. /**
  7.  * @author zhenhuaZhu
  8.  *
  9.  */
  10. public class Display {
  11.     
  12.     public static void displayAll(List list){
  13.         for (Object obj: list) {
  14.                 System.out.println(obj);
  15.         }
  16.     }
  17.     
  18. }

 

step3:页面调用

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ taglib prefix="ft" uri="/WEB-INF/firstTag.tld"%>
  3. <%
  4.     String path = request.getContextPath();
  5.     String basePath = request.getScheme() + "://"
  6.             + request.getServerName() + ":" + request.getServerPort()
  7.             + path + "/";
  8. %>
  9. <%
  10.     List l = new LinkedList();
  11.     l.add("hello");
  12.     l.add("java");
  13.     l.add("world");
  14.     request.setAttribute("l", l);
  15. %>
  16. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  17. <html>
  18.     <head>
  19.         <base href="<%=basePath%>">
  20.         <title>My JSP 'index.jsp' starting page</title>
  21.         <meta http-equiv="pragma" content="no-cache">
  22.         <meta http-equiv="cache-control" content="no-cache">
  23.         <meta http-equiv="expires" content="0">
  24.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  25.         <meta http-equiv="description" content="This is my page">
  26.         <!--
  27.     <link rel="stylesheet" type="text/css" href="styles.css">
  28.     -->
  29.     </head>
  30.     <body>
  31.         <ft:print parameter2="${l}"/>
  32.     </body>
  33. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值