Include css and js file in every jsp page

前端 未结 5 1076
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 14:00

I have common css and js files that i include in every jsp file.

So what\'s the best practice to include them in every page ?

I used to use <%@

5条回答
  •  星月不相逢
    2021-01-03 14:32

    I like using fragments for this, they are standard supported by JSP so no other dependencies are needed. And as you will see it will comes with lot's of other benefits.

    Create a tag (parentpage.tag):

    <%@tag description="Base page" pageEncoding="UTF-8" %>
    
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    
    <%@attribute name="extra_css" fragment="true" %>
    <%@attribute name="footer" fragment="true" %>
    <%@attribute name="header" fragment="true" %>
    
    
     ....
    // insert css that is needed for every page
    
    
    
    
    

    Then you create individual pages that inherit from this tag

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    
        
            // custom css for this page 
        
        
            // footer content
        
        
           // body content
        
    
    
    

提交回复
热议问题