1. 程式人生 > >向jsp中引入公共檔案

向jsp中引入公共檔案

前沿,在網頁開發中,總會存在某幾個.js或者某幾個.css是所有.jsp檔案的公用檔案,為了方便引用

我們把這些在公共的.js及.css檔案放到一個.jsp檔案中,只需要將這個引入所有公共.js及.css的檔案放到需要用到的.jsp檔案中即可

例如:

head.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/noticeService/loadingAndMsg.css" /> <script type="text/javascript" src="<%=request.getContextPath() %>/js/public/jquery.js"
></script> <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> </head>

children.jsp

<%@ include file="/wsp/include/head.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="keywords" content=""> <title>百萬家財燃氣保-宿享版</title> </head> <body> <div class="container">該頁面引用了公共.js及.css</div> </body> </html>