JSP Tag Files in subdirectories, using a single taglib prefix. Is that possible?

前端 未结 3 1297
南方客
南方客 2021-02-20 00:04

I currently have my .tag files declared with:

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

Example of the path of a tag file :

3条回答
  •  野的像风
    2021-02-20 00:29

    A pattern that I follow, even though doesn't address the OP's problem directly, I find it makes the whole situation a lot less painful, which is creating a JSP Fragment where I define all taglibs:

    /WEB-INF/views/taglibs.jspf

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    
    <%@ taglib prefix="layout" tagdir="/WEB-INF/tags/layout" %>
    <%@ taglib prefix="t_users" tagdir="/WEB-INF/tags/users" %>
    <%@ taglib prefix="t_widgetsA" tagdir="/WEB-INF/tags/widgetsA" %>
    <%@ taglib prefix="t_widgetsB" tagdir="/WEB-INF/tags/widgetsB" %>
    

    And then include this JSP Fragment at the top of every JSP file:

    /WEB-INF/views/users/employeeProfile.jsp

    <%@ include file="/WEB-INF/views/taglibs.jspf" %>
    
    
        

    Employee Profile

    ...

提交回复
热议问题