当今由html支持的连接机制(< a href="destination.html">)允许创建有唯一地址的超连接,为了能在超连接上增加上下文相联系的地址,我们需要提供一些嵌入语(比如:"download pdf version," "download word version,"等等)或者使其跳转到页面的另一部分(比如:a "resources"),有时候会导使读者找不到上下文。如果我们把这些附加的地址潜入到一个超连接里,就可以极大的提高页面的使用价值。这些嵌入的连接可以指向另外一些资源,以使我们在同一区域聚集更多需要的信息。
为了能在一个超连接里嵌入一些连接,或许你可能会采用以下方式:
< a href="main_destination.html"
href1="embedded_destination1.html" text1="embedded hypertext1"
href2="embedded_destination2.html" text2="embedded hypertext2"
href3="embedded_destination3.html" text3="embedded hypertext3"
href4="embedded_destination4.html" text4="embedded hypertext4">main hypertext
< /a>
或者以标签嵌套的方式,比如:
< a href="main_destination.html">main hypertext
< a href="embedded_destination1.html">embedded hypertext1< /a>
< a href="embedded_destination2.html">embedded hypertext2< /a>
< a href="embedded_destination3.html">embedded hypertext3< /a>
< a href="embedded_destination4.html">embedded hypertext4< /a>
< /a>
很不幸的是以这种方式根本不能达到要求也不符合html规范,如果这样的话会使得头连接忽略附加的那些连接并且把这些连接罗列出来大家都知道,使得用户能接受一些新功能的关键是在于它的可用性。因此,任何扩展连接的方法都不是行之有效的,而应该采用一种类似于导航条的机制以使用户能轻而易举的理解和接受它。我们可以把一个下拉式的图标安置在超连接旁边,点击该图标就会显示那些嵌入的超连接。正如下图所示:
其实这就是我们所熟悉的动态菜单的思想,但它是和html文本内容相互独立。虽然每一个菜单仅含有几行html代码,但要为每一个含有多重目的文件的超连接都编写这样的代码显然是不切实际的。我们需要一种简单、正式、类似于标记形式的结构,并且易于理解和使用,就像是我们开头提到的那两种方式。这就需要开发者们把注意力集中在内容的是献上而不是规划上。
在我叙述我的解决方法之前,我先提一点,很多支持这种复杂的对于web. xml与它的相关链接标准的工作已经在进行中,比如:xlink 和 xpointer,这俩都是在w3c里定义的标准,允许支持丰富的超链接功能。但这种高级连接标准依然没有被流行的浏览器支持(internet explorer就不支持:xlink),另外,:xlink很复杂,对于一般的web站点是承受不起的。
下面将来简单阐释一下如何用jsp定制标签(custom tags)结合xml来创建丰富的超连接。
jsp 标签(tags)
jsp tags在jsp页面提供了一种可重用性的强大机制,已于读写和维护页面,它使得java
程序员在jsp代码里可以写出xml样式的标签而不是scriptlets,与html标记配合更加协调。这些标签是服务器端的资源,这些资源包含了用来为页面产生内容的应用逻辑。这样就增强了用户界面和”内容生成“逻辑之间的划分。
自定义标签(the custom tag)
从此处下载源代码(download the source code for this article)
创建一个定制标签,首先我们先建立一个描述符(tld)文件,用来描述标签的名字和属性,并把它和一个class文件联系起来。tld文件是基于xml格式的,放在服务器端的web-inf目录里,这些文件是web容器用来验证jsp tags的,下面这个tld文件名字是multilink.tld:
< tag>
< name>multi< /name>
< tagclass>util.tags.multilinktag< /tagclass>
< bodycontent>tagdependent< /bodycontent>
< attribute>
< name>id< /name>
< required>true< /required>
< /attribute>
< attribute>
< name>href< /name>
< required>true< /required>
< /attribute>
< attribute>
< name>text< /name>
< required>true< /required>
< /attribute>
< attribute>
< name>metalinks< /name>
< required>true< /required>
< /attribute>
< attribute>
< name>onmouseover< /name>
< required>false< /required>
< /attribute>
< /tag>
(责任编辑:包春林)