JSTL taglibs not recognized when declared in common header

前端 未结 1 1525
有刺的猬
有刺的猬 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 , 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 ... but of course you can't use 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)
提交回复
热议问题