我是靠谱客的博主 甜美画板,这篇文章主要介绍JSP 简单的layout例子,现在分享给大家,希望可以做个参考。

首先,在WEB-INF目录下新建tags目录,然后,在tags目录下新建文件mainLayout.tag

内容为:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@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页面中,就可以用如下方式引用了

复制代码
1
2
3
4
5
<%@ 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>




复制代码
1

最后

以上就是甜美画板最近收集整理的关于JSP 简单的layout例子的全部内容,更多相关JSP内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部