关于JSP的学习中没有jsp2-example-taglib.tld文件的问题

我在网上学习JSP的过程中,老师在讲自定义标签的过程中,要用到Tomcat安装目录下的:

webapps\examples\WEB-INF\jsp2\jsp2-example-taglib.tld这个文件

很遗憾的是,我的tomcat安装目录里没有这个文件,我自己也不明白这个原因,也许是我tomcat的配置有问题?但是为了解决眼下的问题,我采取的办法就是上网下载了别人的老版的Tomacat安装目录,然后手动找到了这个文件,毕竟只是要用到其中的部分代码而已,所以,为了帮助万一情况跟我类似的朋友,我将该文件的源码贴出来,供大家使用:

jsp2-example-taglib.tld完整代码:

<?xml version="1.0" encoding="UTF-8" ?>
<!--
  Copyright 2004 The Apache Software Foundation

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<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>A tag library exercising SimpleTag handlers.</description>
    <tlib-version>1.0</tlib-version>
    <short-name>SimpleTagLibrary</short-name>
    <uri>/SimpleTagLibrary</uri>
    <tag>
	<description>Outputs Hello, World</description>
        <name>helloWorld</name>
	<tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
	<body-content>empty</body-content>
    </tag>
    <tag>
        <description>Repeats the body of the tag 'num' times</description>
        <name>repeat</name>
        <tag-class>jsp2.examples.simpletag.RepeatSimpleTag</tag-class>
        <body-content>scriptless</body-content>
        <variable>
            <description>Current invocation count (1 to num)</description>
            <name-given>count</name-given>
        </variable>
        <attribute>
            <name>num</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
    <tag>
	<description>Populates the page context with a BookBean</description>
        <name>findBook</name>
	<tag-class>jsp2.examples.simpletag.FindBookSimpleTag</tag-class>
	<body-content>empty</body-content>
	<attribute>
	    <name>var</name>
	    <required>true</required>
	    <rtexprvalue>true</rtexprvalue>
	</attribute>
    </tag>
    <tag>
        <description>
            Takes 3 fragments and invokes them in a random order
        </description>
        <name>shuffle</name>
        <tag-class>jsp2.examples.simpletag.ShuffleSimpleTag</tag-class>
        <body-content>empty</body-content>
        <attribute>
            <name>fragment1</name>
            <required>true</required>
	    <fragment>true</fragment>
        </attribute>
        <attribute>
            <name>fragment2</name>
            <required>true</required>
	    <fragment>true</fragment>
        </attribute>
        <attribute>
            <name>fragment3</name>
            <required>true</required>
	    <fragment>true</fragment>
        </attribute>
    </tag>
    <tag>
        <description>Outputs a colored tile</description>
        <name>tile</name>
        <tag-class>jsp2.examples.simpletag.TileSimpleTag</tag-class>
        <body-content>empty</body-content>
        <attribute>
            <name>color</name>
            <required>true</required>
        </attribute>
        <attribute>
            <name>label</name>
            <required>true</required>
        </attribute>
    </tag>
    <tag>
	<description>
	  Tag that echoes all its attributes and body content
	</description>
	<name>echoAttributes</name>
	<tag-class>jsp2.examples.simpletag.EchoAttributesTag</tag-class>
	<body-content>empty</body-content>
	<dynamic-attributes>true</dynamic-attributes>
    </tag>
    <function>
        <description>Reverses the characters in the given String</description>
        <name>reverse</name>
	<function-class>jsp2.examples.el.Functions</function-class>
	<function-signature>java.lang.String reverse( java.lang.String )</function-signature>
    </function>
    <function>
        <description>Counts the number of vowels (a,e,i,o,u) in the given String</description>
        <name>countVowels</name>
	<function-class>jsp2.examples.el.Functions</function-class>
	<function-signature>java.lang.String numVowels( java.lang.String )</function-signature>
    </function>
    <function>
	<description>Converts the string to all caps</description>
        <name>caps</name>
	<function-class>jsp2.examples.el.Functions</function-class>
	<function-signature>java.lang.String caps( java.lang.String )</function-signature>
    </function>
</taglib>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是myTaglib.tld文件的示例代码,用于配置自定义函数的标签库: ```xml <?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_0.xsd"> <tlib-version>1.0</tlib-version> <short-name>myTaglib</short-name> <uri>http://www.example.com/tags/myTaglib</uri> <function> <name>triangle</name> <function-class>util.com.Triangle</function-class> <function-signature>boolean triangle(double a, double b, double c)</function-signature> </function> </taglib> ``` 在以上代码,我们定义了一个名为“myTaglib”的标签库,它的URI为“http://www.example.com/tags/myTaglib”。其,<function>标签用于定义自定义函数,<name>标签定义函数的名称,<function-class>标签定义函数所在的类,<function-signature>标签定义函数的返回类型和参数列表。 在这个示例,我们定义了一个名为“triangle”的函数,它的返回类型为boolean,参数列表为三个double类型的数值a、b、c。该函数将会在util.com包的Triangle类实现。在JSP页面,我们可以使用以下标签引用该函数: ```jsp <%@ taglib prefix="my" uri="http://www.example.com/tags/myTaglib" %> ... <c:if test="${my:triangle(a, b, c)}"> 可以构成三角形,面积为${util:area(a, b, c)} </c:if> <c:if test="${!my:triangle(a, b, c)}"> 无法构成三角形 </c:if> ``` 在以上代码,我们使用了JSP的<c:if>标签来根据函数的返回值进行条件判断。注意,我们需要使用前缀“my”来引用该标签库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值