【问题标题】:How to define an example in a JSP taglib <tag-file> element?如何在 JSP taglib <tag-file> 元素中定义示例?
【发布时间】:2009-12-14 11:10:06
【问题描述】:

我目前正在编写一堆 JSP 标签供我们的设计人员使用。在我的 .tld 文件中,我有一些 &lt;tag&gt; 和更多 &lt;tag-file&gt; 元素。

现在,我想给标签库的用户一些关于如何使用它们的例子。根据Sun's documentation&lt;tag-file&gt;&lt;tag&gt; 元素都允许有&lt;example&gt; 元素。

这适用于&lt;tag&gt;,但每当我尝试在&lt;tag-file&gt; 中放置示例时,Eclipse 和 Tomcat 都会抛出错误。

有人有这方面的经验吗?

【问题讨论】:

    标签: tomcat jsp-tags


    【解决方案1】:

    &lt;example&gt; 元素是在 Servlet 2.4 / JSP 2.0 中引入的。

    除了将 taglib 根声明为 JSP taglib 2.0,如下所示

    <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/web-jsptaglibrary_2_0.xsd"
        version="2.0">
    

    您是否也在使用支持 Servlet 2.4 / JSP 2.0 的应用服务器?例如 Tomcat 5.x 或更新版本。如果没有,那么您需要升级。如果是这样,那么这个问题:在web.xml 中声明了正确的 Servlet 版本(至少 2.4)吗?如果没有,请确保您这样做:

    <web-app 
        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-app_2_4.xsd"
        version="2.4">
    

    或者,如果您已经在使用支持 Servlet 2.5 的应用服务器(例如 Tomcat 6.x),那么只需声明 Servlet 2.5 是最新的:

    <web-app 
        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-app_2_5.xsd"
        version="2.5">
    

    如果您不想升级应用服务器或更改 web.xml 中的 Servlet API 版本声明,那么您需要接受不能使用 &lt;example&gt; 元素的事实。

    【讨论】:

      【解决方案2】:

      它适用于我在 Tomcat 6.0 上。这是我的文件,

      <tagtoc name="Configuration Components">
        <tag-file>
          <description>Get configured value</description>
          <display-name>get</display-name>
          <name>get</name>
          <path>/META-INF/tags/config/get.tag</path>
          <example>
             <![CDATA[
                     <config:get key="username" echo="true" />
            ]]>
            <usage>
              <comment>
                <p>
                  See config-test.jsp in the example application.
                </p>
              </comment>
            </usage>
          </example>
        </tag-file>
      

      ...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-09
        • 2015-12-25
        • 2012-04-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多