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

王朝java/jsp·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

创建动态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

<%@ 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代码的大量冗余,增加开发与维护成本。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航