Actions An action element can act on implicit objects and other server-side objects
or can define new scripting variables. Actions may affect the current
out stream and use, modify and/or create objects. Actions may, and often
will, depend on the details of the specific request object received by
the JSP page.
The JSP specification includes some action types that are standard and
must be implemented by all conforming JSP containers. New action types
are introduced using the taglib directive.
The syntax for action elements is based on XML. Actions follow the XML
syntax for elements with a opening tag, a body and a closing tag. Below
is a list of the standard actions.
useBean
This action allows a page to use a Java Bean. JavaBeans are Java components
You must first import the class in the page
directive to instantiate a bean.
<jsp:useBean id="
BeanName"
scope="page|request|session|application"
class="package.class" />
</jsp:useBean>
setProperty
The jsp:setProperty action is used in conjunction with the jsp:useBean
action to set bean properties. The syntax is:
<jsp:setProperty
name="beanName"
property="*|propertyName"
value="propertyValue" />
The property attribute can be used in any of the following ways:
property="*"
property="propertyName"
property="propertyName" value="propertyValue"
property="propertyName" param="parameterName"
getProperty
The jsp:getProperty action is used in conjunction with the jsp:useBean
action to get bean properties. The syntax is:
<jsp:getProperty name="beanName"
property="propertyName" />
param
The jsp:param element is used to provide key/value information. This
element is used in the jsp:include, jsp:forward and jsp:plugin elements.
The syntax is:
<jsp:param name="parameterName"
value="parameterValue" />
Example:
<jsp:include page="includePage.jsp"
flush="true|false">
<jsp:param name="parameterName"
value="parameterValue" />
</jsp:include>
forward
This element forwards a client request to an HTML file, JSP file, or
servlet for processing.
The syntax is:
<jsp:forward page="page.jsp" />
Or:
<jsp:forward page="page.jsp" >
<jsp:param name="parameterName"
value="parameterValue" />
</jsp:forward>
include
There are two ways to include a file in a JSP page. First, the include
directive, second, the jsp:include action. The jsp:include action can
include data in a JSP page from another file, without parsing the data.
The jsp:include has only two attributes; the relative URL, and the boolean
flush attribute. The syntax is:
<jsp:include page="includePage.jsp"
flush="true|false" />
Or:
<jsp:include page="includePage.jsp"
flush="true|false">
<jsp:param name="parameterName"
value="parameterValue" />
</jsp:include>
plugin
This action is used to download a Java plugin to the client Web browser
to execute an applet or Bean. The <jsp:plugin> tag is replaced by
either an <object> or <embed> tag. There are quite a number
of the attributes for the <jsp:plugin> tag. They provide configuration
data for the presentation of the element.
The syntax is:
<jsp:plugin type="
bean|applet"
code="
objectCode"
codeBase="
objectCodeBase"
{align="alignment"}
{archive="archiveList"}
{height="height"}
{hspace="hspace"}
{jreversion="jreversion"}
{name="componentName"}
{vspace="vspace"}
{width="width"}
{nspluginurl="url"}
{iepluginurl="url"}
>
{
<jsp:params>
<jsp:param name="paramName" value="paramValue" />
</jsp:params>
}
{
<jsp:fallback>
Arbitrary text...
</jsp:fallback>
}
</jsp:plugin>
The <jsp:param> elements indicate the parameters to the Applet
or JavaBeans component. The <jsp:fallback> element indicates the
content to be used by the client browser if the plugin cannot be started
(either because OBJECT or EMBED is not supported by the client browser
or due to some other problem).
For example:
<jsp:plugin type="applet"
code="zhou.class" codeBase="/myClass/zhou"
align="center" height="200" width="300">
<jsp:params>
<jsp:param name="zhouName" value="nongjian" />
</jsp:params>
<jsp:fallback>
Sorry, your plugin failed to initialize!
</jsp:fallback>
</jsp:plugin>
|