Invalid tagdir attribute while web-fragment is used

邮差的信 提交于 2019-12-07 19:24:58

问题


I am using web-fragment feature to maintain my JSPs and tags in a jar, and using this approach, my JSP pages are unable to find the tagdir, and cause "The value of the tagdir attribute for this tag library is invalid."

Here is the structure in my jar.

META-INF
-- resources
    -- WEB-INF
        -- tags
            -- mytag.tag
    -- mypage.jsp
-- web-fragment.xml

In mypage.jsp, I specify the taglib as following:

And I got these errors:
mypage.jsp:7:4: The taglib directive must specify either the "uri" or "tagdir" attribute.

mypage.jsp:7:33: The value of the tagdir attribute for this tag library is invalid.

It seems like under this approach, it cannot find the tagdir. I tried the same structure in my war with web.xml, and it was able to find the tags. So I wonder if there is any way I can use the similar solution with web-fragment approach.


回答1:


You don't need WEB-INF in the web-fragment project. Use this structure instead:

web-fragment project:

META-INF/
-- resources/
   -- tags/
      -- mytag.tag
   -- mypage.jsp
-- web-fragment.xml

Everything inside the resources directory will now be available to referencing projects as if they were deployed inside WEB-INF.

web project:

WEB-INF/
-- tags/
   -- othertag.tag
   -- (mytag.tag)
-- otherpage.jsp
-- (mypage.jsp)

So to reference mytag.tag from the web project:

<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
...
<my:mytag ... />

As for the errors you are seeing, I don't know what you tried, but here's how you'd do it:

for a .tag you must specify tagdir and set it to the tag's folder:

<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>

for a .tld you must specify uri and set it to the tld's URI:

<%@ taglib prefix="mytld" uri="http://example.com/tld/my" %>


来源:https://stackoverflow.com/questions/18157264/invalid-tagdir-attribute-while-web-fragment-is-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!