一般来说,我们做网站的时候,其实页脚、横幅、左菜单都是一样的。 例如:
每页写一次的话,会浪费资源。 通常,我们的解决方案是使用网络模板。 其实很简单的一点是,使用jsp:include page='url'/标记,将重用的代码写在一个页面上并引用。
实例:
main.jsp :
%@ page contentType='text/html; charset=UTF-8' %
html
头戴
title模板页面样本/title
/head
实体
%-- onetablelaysoutallofthecontentforthispage---%
table width='100%' height='100% '
tr
%--头节节节--%
TD width=' 150 ' valign=' top ' align=' left ' bgcolor=' # ccffcc '
JSP :包含page=' header.JSP ' /
/td
/tr
tr
%----主内容部分--- %
td height='100%' width='* '
table width='100%' height='100% '
tr
%-- Sidebar section --%
td valign='top' height='15% '
JSP : include page=' sidebar.JSP ' /
/td
%--内容区段--%
td valign='top' height='* '
JSP :包含页=' index content.JSP ' /
/td
/tr
/table
/td
/tr
tr
%----footersection----%
td valign='bottom' height='15% '
JSP : include page=' footer.JSP ' /
/td
/tr
/table
/body
/html
然后在相应的页面上写下我们设定的代码就可以了。