现在的位置: 首页 > 综合 > 正文

JSP 简单的layout例子

2019年07月23日 ⁄ 综合 ⁄ 共 1018字 ⁄ 字号 评论关闭

首先,在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>

这里还需要引入jstl的标签(PS: 这鸟博客提示有非法的uri)

使用:

在其他的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>


抱歉!评论已关闭.