您的位置:首页 > Web前端 > JavaScript

如何实现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>
然后相应的页面写上我们设置的代码就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: