Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 重用自定义JSP标记_Spring_Tomcat_Split_Jsp Tags_Code Reuse - Fatal编程技术网

Spring 重用自定义JSP标记

Spring 重用自定义JSP标记,spring,tomcat,split,jsp-tags,code-reuse,Spring,Tomcat,Split,Jsp Tags,Code Reuse,我想把我的Spring/JSP/Maven/tomcatwebapp项目分成几个不同的项目。因此,它们中的每一个都将充当一个独立的web应用程序。 现在,我想在所有项目中使用相同的自定义JSP标记,但我不想复制WEB-INF/tag文件夹EveryShare。 如何在共享项目中定义它,并在所有依赖项目中重用它 我通过将tld放在公共项目的src/main/java/META-INF文件夹中实现了这一点 e、 g.通用tld <?xml version="1.0" encoding="ISO

我想把我的Spring/JSP/Maven/tomcatwebapp项目分成几个不同的项目。因此,它们中的每一个都将充当一个独立的web应用程序。 现在,我想在所有项目中使用相同的自定义JSP标记,但我不想复制WEB-INF/tag文件夹EveryShare。
如何在共享项目中定义它,并在所有依赖项目中重用它

我通过将tld放在公共项目的src/main/java/META-INF文件夹中实现了这一点

e、 g.通用tld

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" 
  "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>Custom common Tag Library</shortname>
    <uri>http://www.mysite.be/tags/common</uri>
    ...

1
1.1
自定义公共标记库
http://www.mysite.be/tags/common
...
然后它将JSP放在项目中(包括共享项目):



免责声明:我这么做已经很久了,所以我希望我没有忘记任何事情,也不确定这是否(仍然)是最好的选择。

在前面的答案的基础上,假设您使用的是Maven,那么您的通用taglib项目应该如下所示:

-src
--main
---resources
-----META-INF
-----taglib.tld
-----tags
-------tag1.tag
-------tag2.tag
<?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 web-jsptaglibrary_2_0.xsd"
    version="2.0">

    <description>JSP 2.0 Tag File Library for Spring MVC and Bootstrap
    </description>
    <tlib-version>1.0</tlib-version>
    <short-name>my-taglib-name</short-name>
    <uri>http://my.taglib.namespace</uri>
    <tag-file>
        <name>tag1</name>
        <path>/META-INF/tags/tag1.tag</path>
    </tag-file>
    <tag-file>
        <name>tag2</name>
        <path>/META-INF/tags/tag2.tag</path>
    </tag-file>
</taglib>
其中taglib.tld的内容如下所示:

-src
--main
---resources
-----META-INF
-----taglib.tld
-----tags
-------tag1.tag
-------tag2.tag
<?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 web-jsptaglibrary_2_0.xsd"
    version="2.0">

    <description>JSP 2.0 Tag File Library for Spring MVC and Bootstrap
    </description>
    <tlib-version>1.0</tlib-version>
    <short-name>my-taglib-name</short-name>
    <uri>http://my.taglib.namespace</uri>
    <tag-file>
        <name>tag1</name>
        <path>/META-INF/tags/tag1.tag</path>
    </tag-file>
    <tag-file>
        <name>tag2</name>
        <path>/META-INF/tags/tag2.tag</path>
    </tag-file>
</taglib>

SpringMVC和Bootstrap的JSP 2.0标记文件库
1
我的标记库名称
http://my.taglib.namespace
tag1
/META-INF/tags/tag1.tag
tag2
/META-INF/tags/tag2.tag
然后,您就可以以正常的方式在依赖项目中引用taglib

<%@ taglib uri="http://my.taglib.namespace" prefix="t"%>

有关更多指导,请参阅文档: