Preface

Comment

Declaration

Expression

Scriptlet

EL Expression

Directives

Attribute Directive

Include Directive

Page Directive

Tag Directive

Taglib Directive

Variable Directive

Standard Actions

<jsp:attribute>

<jsp:body>

<jsp:element>

<jsp:doBody>

<jsp:forward>

<jsp:getProperty>

<jsp:include>

<jsp:invoke>

<jsp:output>

<jsp:plugin>

<jsp:root>

<jsp:setProperty>

<jsp:text>

<jsp:useBean>

<jsp:element>

Dynamically generates an XML element.

JSP Syntax

(<jsp:element name="elementName"	
 ( /> | >  ( any elements or text </jsp:element> ))
) 
| ( <jsp:element name="elementName">
       [ <jsp:attribute name="attributeName" 	
         [ trim="true | false" ]
      ( /> | (any elements or text </jsp:attribute> ) ) ]+ 
      [ <jsp:body> any elements or text </jsp:body> ]
    </jsp:element>
  )

XML Syntax

Same as JSP syntax.

Examples

This example generates an HTML header tag with a lang attribute:

<jsp:element name="${content.headerName}"	
   xmlns:jsp="http://java.sun.com/JSP/Page">	
   <jsp:attribute name="lang">${content.lang}</jsp:attribute>	
   <jsp:body>${content.body}</jsp:body>	
</jsp:element>

The name attribute identifies the generated tag's name. The jsp:attribute tag generates the lang attribute. The body of the jsp:attribute tag identifies the value of the lang attribute. The jsp:body tag generates the body of the tag. The output of this example jsp:element could be:

<h1 lang="fr">Heading in French</h1>

Description

The jsp:element action is used to dynamically define the value of the tag of an XML element. This action can be used in JSP pages, tag files and JSP documents.

A jsp:element action has one mandatory attribute, name, of type String. The value of the name attribute is used as that of the tag of the element generated. The jsp:element action can have a body. Two forms are valid, depending on whether the element is to have attributes or not. In the first form, no attributes are present:

<jsp:element name="name">	
   optional body	
</jsp:element>

In the second form, zero or more attributes are requested, using jsp:attribute and jsp:body, as appropriate.

<jsp:element name="name">	
   [jsp:attribute]+	
   [jsp:body]	
</jsp:element>

The one valid, mandatory, attribute of jsp:element is its name. Unlike other standard actions, the value of the name attribute must be given as an XML-style attribute and cannot be specified using jsp:attribute This is because jsp:attribute has a special meaning when used in the body of jsp:element.

Attributes

See Also



宏飞网络是你学习web开发、测试web程序实例、和培养职业技能的首选网站。我们提供例子也许有些简单,但对理解基本概念有帮助。

我们尽量避免在教程、参考及例子中出现错误,但不能保证所有的内容都是正确的。

你使用本网站时,我们默认你已经阅读并接受了我们的隐私政策。

Copyright 2003-2011宏飞网络 版权所有