首先,在WEB-INF目录下新建tags目录,然后,在tags目录下新建文件mainLayout.tag
内容为:
<%@tag pageEncoding="UTF-8"%>
<%@tag trimDirectiveWhitespaces="true"%>
<%@tag body-content="scriptless"%>
<%@ attribute name="title" required="true" type="java.lang.String" %>
<c:set var="rootpath" value="${ pageContext.request.contextPath}" scope="request" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${ title}</title>
<link rel="stylesheet" type="text/css" href="${ rootpath}/res/css/cloud.css" />
<script type="text/javascript" src="${ rootpath}/res/js/cloud.js"></script>
</head>
<body>
<div class="main">
<div class="top">this is my first layout jsp</div>
<div class="mbody">
<jsp:doBody></jsp:doBody>
</div>
<div class="bright">
this is bottom for page
</div>
</div>
</body>
</html>
使用:
在其他的jsp页面中,就可以用如下方式引用了
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="ot" tagdir="/WEB-INF/tags" %>
<ot:mainLayout title="腾讯首页">
<h1>this is layout display centent</h1>
</ot:mainLayout>