Section A.3. Standard Actions

   

A.3 Standard Actions

The JSP 1.2 specification provides several XML-compliant actions in the form of tags that allow you to include external pages, forward control to another page, or use a JavaBean or the Java plugin. This section describes these actions.

Table A.3. taglib Directive Attributes

Attribute

Description

Notes

prefix

Tag prefix

(required) Defines the prefix you will use to call the custom tags.

uri

Library location

(required) Specifies location of the tag library namespace.

A.3.1 <jsp:forward>

This action is used to end the execution of the current template and forward the request to another URL. The specified URL can be another JSP, an HTML page, a servlet, or other Web resources. The resource is specified as relative to the root of the current application.

Usage:

 <jsp:forward page='/javaforcf/secret.jsp' /> 

You can also use the <jsp:param> action to forward request parameters to the specified page:

 <jsp:forward page = '/javaforcf/secret.jsp'>  <jsp:param name='userid' value='admin' /> </jsp:forward> 
Table A.4. <jsp:forward> Action Attributes

Attribute

Description

Notes

page

Page location

(required) Specifies the location of the page to forward to, relative to the root of the application.

A.3.2 <jsp:getProperty>

This action is used to output the specified property value from a JavaBean. The output value is a string. The specified bean must first be instantiated with the <jsp:useBean> action.

Usage:

 <jsp:getProperty name='cart' property = 'orderid' /> 
Table A.5. <jsp:getProperty> Action Attributes

Attribute

Description

Notes

name

Name of bean

(required) Specifies name of a bean, which is already instantiated in any scope.

property

Property of bean

(required) Specifies the bean property to retrieve the value of.

A.3.3 <jsp:include>

This action is used to include a static or dynamically referenced file at run time. Because of when the file is included, files included using the <jsp:include> action do not share page or request-scoped variables with the calling page. For this reason, files included with the action cannot process directives. This is in distinction to the include directive.

Usage:

 <jsp:include file='header.jsp' flush='true' /> 
Table A.6. <jsp:include> Action Attributes

Attribute

Description

Notes

flush

Flush buffer

(optional) Specifies whether or not to flush the output buffer before including the file. Default value is false.

page

Page location

(required) Specifies location of the file to be included.

Note that the page attribute can be the result of a runtime expression; that is, it can be dynamically specified. In JSP 1.1, the flush attribute was required, and its only possible value was true.

Also, you can append parameters to the original request with the <jsp:param> action. If the parameter already exists, the new value overwrites it. Multiple parameters can be specified in a comma-separated list.

A.3.4 <jsp:param>

This action allows you to pass parameters in the request scope. It is used within the bodies of <jsp:forward> , <jsp:include> , or <jsp:plugin> .

Usage:

 <jsp:param name='userid'   value='<%=request.getParameter(\'userid\')%>' /> 
Table A.7. <jsp:param> Action Attributes

Attribute

Description

Notes

name

Parameter name

(required) Name of the parameter.

value

Parameter value

(required) Value of the parameter.

A.3.5 <jsp:params>

The <jsp:params> action wraps multiple <jsp:param> actions for passing to an applet.

Usage:

 <jsp:params>  <jsp:param name='Dept' value='Engineering' /> <jsp:param name='Emp' value='Dilbert' /> </jsp:params> 
Table A.8. <jsp:params> Action Attributes

Attribute

Description

Notes

name

Parameter name

(required) Name of the parameter.

value

Parameter value

(required) Value of the parameter.

A.3.6 <jsp:plugin>

The <jsp:plugin> action allows you to embed an applet or a JavaBeans component directly in the JSP returned to the browser. It automatically generates the <embed> or <object> tags for you.

Usage:

 <jsp:plugin  type = 'applet' code = 'productivityChart.class' codebase = 'intranet' width = '300' height = '400' /> 
Table A.9. <jsp:plugin> Action Attributes

Attribute

Description

Notes

align

Alignment

(optional) Specifies alignment of applet area.

archive

Applet classes

(optional) Additional classes or resources, specified by URL, that must be loaded.

code

Class name

(required) Specifies name of the class containing the applet or bean.

codebase

Class location

(required) Specifies relative URL location of the class specified in the code attribute.

height

Height in pixels

(optional) Specifies height of the applet area.

hspace

Horizontal border in pixels

(optional) Specifies number of pixels wide the border on the side of the applet should be.

iepluginurl

URL for IE plugin

(optional) Location of the Java plugin for MS Internet Explorer.

jreversion

JRE version

(optional) Specifies minimum requirement for the Java Runtime Engine version. Default is 1.1.

name

Applet name

(optional) A name for the applet to keep it distinguished from other applets or beans on the page.

nspluginurl

URL for Netscape plugin

(optional) Location of the Java plugin for Netscape.

title

Label

(optional) A text description for the applet, which can appear in mouseover.

type

Object type

(optional) Whether the attribute is an applet or a bean.

vspace

Vertical border in pixels

(optional) Defines a pixel border above and below the applet.

width

Width in pixels

(optional) Width of the applet.

Many of these attributes correspond exactly to their HTML counterparts.

A.3.7 <jsp:setProperty>

The <jsp:params> action wraps multiple <jsp:param> actions for passing to an applet.

Usage:

 <jsp:setProperty name='thisBook'       property='author'      value='JiminyChristmas'      /> 

Note that this is equivalent to the following scriptlet:

 <% thisBook.setAuthor('JiminyChristmas'); %> 
Table A.10. <jsp:setProperty> Action Attributes

Attribute

Description

Notes

name

Bean name

(required) Name of the bean containing the property to be set.

param

Request parameter

(optional) Specifies the request parameter whose value will be set to the bean property value. Use of this attribute obviates use of the value attribute.

property

Bean property

(required) Specifies the property to be set.

value

Set value

(optional) Sets the value of the specified property. Can be any runtime expression that evaluates to a String.

A.3.8 <jsp:useBean>

The <jsp:useBean> action checks for an instance of a bean in the given class and scope. If one is found, it is referenced with the id attribute. If an instance is not found, it instantiates the bean. The bean is then available for processing by referencing the id and scope .

Usage:

 <jsp:useBean id='myBean'> 
Table A.11. <jsp:useBean> Action Attributes

Attribute

Description

Notes

beanName

Bean name

(optional) Specifies name of the bean component you are using to instantiate the bean. The same as the name of the bean in the instantiate() method of java.beans.Beans .

class

Class name

(optional) Used to specify class of the bean you are instantiating.

  id  

Bean reference

(required) Specifies name by which you will reference the bean being instantiated.

type

Variable type

(optional) Sets the type of scripting variable to be used as a bean and is defined by the id attribute. The class that the bean gets cast to.


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net