如何实现JSP网页模板 JSP网页母版
2016-02-02 21:47
666 查看
一般情况下,我们做网站的时候,其实,页脚,横幅,左菜单都是一样的
如果在每个页面都写一次的话,就造成了资源浪费。通常情况下,我们的解决办法就是使用网络模板。其实很简单就是用来一个<jsp:include page="url"/>标签,将重复使用的代码写到一个页面上,然后将其引用过来。
实例:
main.jsp:
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Template Page Sample</title>
</head>
<body >
<%-- One table lays out all of the content for this page --%>
<table width="100%" height="100%">
<tr>
<%-- Header section section --%>
<td width="150" valign="top" align="left" bgcolor="#CCFFCC">
<jsp:include page="header.jsp"/>
</td>
</tr>
<tr>
<%-- Main content section --%>
<td height="100%" width="*">
<table width="100%" height="100%">
<tr>
<%-- Sidebar section --%>
<td valign="top" height="15%">
<jsp:include page="sidebar.jsp"/>
</td>
<%-- Content section --%>
<td valign="top" height="*">
<jsp:include page="indexContent.jsp"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<%-- Footer section --%>
<td valign="bottom" height="15%">
<jsp:include page="footer.jsp"/>
</td>
</tr>
</table>
</body>
</html>
然后相应的页面写上我们设置的代码就可以了。
如果在每个页面都写一次的话,就造成了资源浪费。通常情况下,我们的解决办法就是使用网络模板。其实很简单就是用来一个<jsp:include page="url"/>标签,将重复使用的代码写到一个页面上,然后将其引用过来。
实例:
main.jsp:
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Template Page Sample</title>
</head>
<body >
<%-- One table lays out all of the content for this page --%>
<table width="100%" height="100%">
<tr>
<%-- Header section section --%>
<td width="150" valign="top" align="left" bgcolor="#CCFFCC">
<jsp:include page="header.jsp"/>
</td>
</tr>
<tr>
<%-- Main content section --%>
<td height="100%" width="*">
<table width="100%" height="100%">
<tr>
<%-- Sidebar section --%>
<td valign="top" height="15%">
<jsp:include page="sidebar.jsp"/>
</td>
<%-- Content section --%>
<td valign="top" height="*">
<jsp:include page="indexContent.jsp"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<%-- Footer section --%>
<td valign="bottom" height="15%">
<jsp:include page="footer.jsp"/>
</td>
</tr>
</table>
</body>
</html>
然后相应的页面写上我们设置的代码就可以了。
相关文章推荐
- javascript异步过程
- BZOJ 1013: [JSOI2008]球形空间产生器sphere
- JSTL不同版本和EL表达式的关联
- 如何在JavaScript里取session的值
- 什么是javaScript闭包
- JavaScript基础笔记集合
- 立即执行函数表达式 项目经常用到js 代码Module模式
- 不学就吃亏的underscorejs类库学习示例 ——(集合篇)
- Ajax经典总结
- ace布置小作业: 制作一个简单的电话号码归属地查询软件:JSON解析和Volly发送get请求
- JavaScript——动态属性
- django模板导入外部js和css等文件
- 初探内联方式的 onload="doSomething()"为何要加"()"?而js代码的 onload="doSomething" 和 addEventListener 为何不加"()"?
- 前端--关于javascript函数
- Json 中对Key为空的判断
- underscorejs-partition学习
- underscorejs-size学习
- underscorejs-toArray学习
- underscorejs-sample学习
- underscorejs-shuffle学习