瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理


          首先建立自己的函數(shù):
          package com.struts;

          public class MyFunction {
             public static String welcome(String user){
              String welcome="welcome  "+user;
              return welcome;
             }
          }
          然后在項(xiàng)目的web-inf下創(chuàng)建一個(gè)tld文件myFunction.tld用來注冊(cè)函數(shù)內(nèi)容如下:
          <?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">
             
            <description>myfunction</description>
            <display-name>myfunction</display-name>
            <tlib-version>1.0</tlib-version>
            <short-name>myfunction</short-name>
            <uri>http://com.struts/myfunctions</uri>//定義一個(gè)資源地址

            <function>
              <name>welcome</name>
              <function-class>com.struts.MyFunction</function-class>//類
              <function-signature>java.lang.String welcome(java.lang.String)</function-signature>//方法,返回值,參數(shù)類型
            </function>
            </taglib>
          然后是測(cè)試頁面:test_myfunction.jsp

          <%@ page language="java" contentType="text/html; charset=GB18030"
              pageEncoding="GB18030"%>
          <%@ taglib prefix="myfunction" uri="http://com.struts/myfunctions" %>//引入自定義函數(shù)
          <!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=GB18030">
          <title>test myFunction</title>
          </head>
          <body>
          <h1>test_myfunction</h1><hr color="blue">
          <li>test-jstl-myFunction</li><br>
          (use-myfunction):<font color="red">${myfunction:welcome("Tom")}</font><br>//用el表達(dá)式調(diào)用方法

          </body>
          </html>


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 固阳县| 奉化市| 通州区| 昌吉市| 广东省| 铁力市| 万荣县| 郎溪县| 观塘区| 土默特左旗| 高安市| 礼泉县| 东城区| 白沙| 红安县| 于都县| 鹰潭市| 杭锦后旗| 喀喇沁旗| 兰考县| 凌源市| 手游| 荣昌县| 甘南县| 宁都县| 肃北| 天全县| 宜丰县| 建水县| 无棣县| 西贡区| 罗源县| 大理市| 兴安盟| 石渠县| 静宁县| 库伦旗| 灌云县| 镇江市| 霍邱县| 临泉县|