Writing Action Element in XML Format

This section describes the syntax of writing Action Elements in XML format for a JSP document. Commonly used standard action elements are: useBean, setProperty, getProperty, include, and forward.

Writing Action Elements in XML format for a JSP Document is also easy. See syntax below:

<action_name attribute=value ...>...</action_name>.

However, JSP 2.1 supports a large number of standard actions for you to remember:

The most commonly used action element is probably the "useBean" action. More tutorials on "useBean" are provided later in the book.

"element" is a very interesting action element. It can be used with "attribute" and "body" actions to build XML elements in the returning response. Here is a simple JSP Document using "element", "attribute" and "body" actions.

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
<!-- Element_Action.jspx
 - Copyright (c) 2012, HerongYang.com, All Rights Reserved.
-->
<jsp:directive.page contentType="text/html"/>
<jsp:element name="html">
 <jsp:element name="body">
  <jsp:body>
   <jsp:text>
Hello world! - Using "element" action
   </jsp:text>
  </jsp:body>
 </jsp:element>
</jsp:element>
</jsp:root>

If you open this JSP page with a Web browser, you should see:

Hello world! - Using "element" action 

If you open the source code of the Web browser output, you should see:

<html><body>
Hello world! - Using "element" action
   </body></html>

See the next section for more tutorial examples on using Action Elements and other types of JSP elements in JSP Document format.

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

Syntax of JSP Pages and JSP Documents

 Syntactic Elements of a JSP Page

 JSP Document - JSP Page in XML Format

 Writing Scriptlet Element in XML Format

 Writing Directive Element in XML Format

Writing Action Element in XML Format

 "include" Directive and Action Elements

 Execution Result of CurrentTime.jspx

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version