注册
 找回密码
 注册
江西广告网
查看: 364|回复: 0
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

1
跳转到指定楼层
发表于 2009-1-14 08:27:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x
创建动态Web页面的最基本的办法是为每个页面创建独立的JSP文件。图16-2和图16-3分别为tilestaglibs应用的主页index.jsp和产品页面product.jsp。 本节介绍的tilestaglibs应用的源程序位于配套光盘的sourcecode/tilestaglibs/version1/tilestaglibs目录下。如果要在Tomcat上发布这个应用,只要把version1目录下的整个tilestaglibs子目录拷贝到CATALINA_HOME/webapps目录下即可。 图16-2 tilestaglibs应用的主页index.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">roducts</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">age-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">roducts</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代码的大量冗余,增加开发与维护成本。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表