JSTL taglibs not recognized when declared in common header

前端 未结 1 1523
有刺的猬
有刺的猬 2021-02-14 05:28

I had the idea a while back to put all of my taglib declarations (uri\'s, etc) in a common header file so I don\'t have to manually write them into all of my JSPs. Initially, t

相关标签:
1条回答
  • 2021-02-14 05:45

    This is expected behaviour.

    When you use <jsp:include>, it executed the target in a separate request, and then includes the output in the including JSP. It doesn't include the source of the included target, it includes the output. The means by which that target output is generated is lost.

    To do what you're trying to do, you need to use <% include %> directives:

    <%@ include file="/WEB-INF/jsp/include/header.jsp" %>
    

    This will incline the literal text of header.jsp into your page. Of course, by doing that, you can no longer pass parameters to it, so you'd need to set that as a page context attribute (e.g. using <c:set>... but of course you can't use <c:set> until you've done your include...).

    Essentially, it's not really worth the hassle. Taglib declarations are annoying boilerplate, but hard to get rid of.

    0 讨论(0)
提交回复
热议问题