如何实现JSP网页模板 JSP网页母版

 

一般情况下,我们做网站的时候,其实,页脚,横幅,左菜单都是一样的,如:


如果在每个页面都写一次的话,就造成了资源浪费。通常情况下,我们的解决办法就是使用网络模板。其实很简单就是用来一个<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>
然后相应的页面写上我们设置的代码就可以了。
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值