点击这里给我发消息 点击这里给我发消息

采用基本JSP语句创建复合式网页

添加时间:2010-1-5
    相关阅读: 网页 开发 页面 程序 JSP 维护
创建动态Web页面的最基本的办法是为每个页面创建独立的JSP文件。图16-2和图16-3分别为tilestaglibs应用的主页index.jsp和产品页面product.jsp。

本节介绍的tilestaglibs应用的源程序位于配套光盘的sourcecode/tilestaglibs/version1/tilestaglibs目录下。如果要在Tomcat上发布这个应用,只要把version1目录下的整个tilestaglibs子目录拷贝到CATALINA_HOME/webapps目录下即可。

采用基本JSP语句创建复合式网页(图一)

图16-2 tilestaglibs应用的主页index.jsp

采用基本JSP语句创建复合式网页(图二)
图16-3 tilestaglibs应用的产品页面product.jsp

例程16-1和例程16-2分别为index.jsp和product.jsp的源代码。例程16-1 index.jsp
    例程16-1 index.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>
<html>
   <head>
      <title>TilesTaglibs Sample</title>
   </head>
   <body >
      <%-- One table lays out all of the content for this page --%>
      <table width="100%" height="100%" >
         <tr>
            <%-- Sidebar--%>
            <td width="150" valign="top" align="left" bgcolor="#CCFFCC">
               <table>
                  <tr>
                     <%-- Sidebar top --%>
                     <td width="150" height="65" valign="top" align="left">
                        <a href="">
                           <img src="chinese.gif" border="0" /></a>
                        <a href="">
                           <img src="usa.gif" border="0"/></a>
                      </td>
                  </tr>
                  <tr>
                     <%-- Sidebar bottom --%>
                     <td>
                        <font size="5">Links</font><p>
                        <a href="index.jsp">Home</a><br>
                        <a href="product.jsp">Products</a><br>
                        <a href="">Hot Link1</a><br>
                        <a href="">Hot Link2</a><br>
                        <a href="">Hot Link3</a><br>

                     </td>
                  </tr>
               </table>
            </td>
            <%-- Main content--%>
            <td valign="top" height="100%" width="*">
               <table width="100%" height="100%">
                  <tr>
                     <%-- Header--%>
                     <td valign="top" height="15%">
                        <font size="6">Welcome to ABC Inc.</font>
                        <hr>
                     </td>
                  <tr>
                 <tr>
                     <%-- Content--%>
                     <td valign="top" height="*">
                        <font size="4">Page-specific content goes here</font>
                     </td>
                  </tr>
                  <tr>
                     <%-- Footer--%>
                     <td valign="bottom" height="15%">
                        <hr>
                        Thanks for stopping by!
                     </td>
                  </tr>
               </table>
            </td>
         </tr>
      </table>
   </body>
</html>

例程16-2 product.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>
<html>
   <head>
      <title>TilesTaglibs Sample</title>
   </head>
   <body >
      <%-- One table lays out all of the content for this page --%>
      <table width="100%" height="100%" >
         <tr>
            <%-- Sidebar--%>
            <td width="150" valign="top" align="left" bgcolor="#CCFFCC">
               <table>
                  <tr>
                     <%-- Sidebar top --%>
                     <td width="150" height="65" valign="top" align="left">
                        <a href="">
                           <img src="chinese.gif" border="0" /></a>
                        <a href="">
                           <img src="usa.gif" border="0"/></a>
                      </td>
                  </tr>
                  <tr>
                     <%-- Sidebar bottom --%>
                     <td>
                         <font size="5">Links</font><p>
                        <a href="index.jsp">Home</a><br>
                        <a href="product.jsp">Products</a><br>
                        <a href="">Hot Link1</a><br>
                        <a href="">Hot Link2</a><br>
                        <a href="">Hot Link3</a><br>
                     </td>
                  </tr>
               </table>
            </td>
            <%-- Main content--%>
            <td valign="top" height="100%" width="*">
               <table width="100%" height="100%">
                  <tr>
                     <%-- Header--%>
                     <td valign="top" height="15%">
                        <font size="6">Welcome to ABC Inc.</font>
                        <hr>
                     </td>
                  <tr>
                 <tr>
                     <%-- Content--%>
                     <td valign="top" height="*">
                        <font size="4">Products</font> <p>
             <li>product1</li> <br>
                        <li>product2</li> <br>
                        <li>product3</li> <br>
                     </td>
                  </tr>
                  <tr>
                     <%-- Footer--%>
                     <td valign="bottom" height="15%">
                        <hr>
                        Thanks for stopping by!
                     </td>
                  </tr>
               </table>
            </td>
         </tr>
      </table>
   </body>
</html>

由例程16-1和例程16-2可以看出,在index.jsp和product.jsp文件中,仅仅粗体字标识的代码块不是重复代码,其余部分均为重复代码。如果网页的相同部分发生需求变更,必须手工修改所有的JSP文件。可见,采用基本的JSP语句来编写上述网页,会导致JSP代码的大量冗余,增加开发与维护成本

本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册