blob: 16b974edebe13f2313e0592b4859a1bb4035aa46 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Fri Jun 15 16:53:35 PDT 2001 -->
<TITLE>
Apache Struts API Documentation: Package org.apache.struts.taglib.bean
</TITLE>
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">
</HEAD>
<BODY BGCOLOR="white">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/html/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<H2>
Package org.apache.struts.taglib.bean
</H2>
The "struts-bean" tag library contains JSP custom tags useful in defining new
beans (in any desired scope) from a variety of possible sources, as well as a
tag to render a particular bean (or bean property) to the output response.
<P>
<B>See: </B>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#package_description"><B>Description</B></A>
<P>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Class Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="CookieTag.html">CookieTag</A></B></TD>
<TD>Define a scripting variable based on the value(s) of the specified
cookie received with this request.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="CookieTei.html">CookieTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>cookie</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="DefineTag.html">DefineTag</A></B></TD>
<TD>Define a scripting variable based on the value(s) of the specified
bean property.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="DefineTei.html">DefineTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>define</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="HeaderTag.html">HeaderTag</A></B></TD>
<TD>Define a scripting variable based on the value(s) of the specified
header received with this request.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="HeaderTei.html">HeaderTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>header</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="IncludeTag.html">IncludeTag</A></B></TD>
<TD>Define the contents of a specified intra-application request as a
page scope attribute of type <code>java.lang.String</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="IncludeTei.html">IncludeTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>include</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="MessageTag.html">MessageTag</A></B></TD>
<TD>Custom tag that retrieves an internationalized messages string (with
optional parametric replacement) from the <code>ActionResources</code>
object stored as a context attribute by our associated
<code>ActionServlet</code> implementation.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="PageTag.html">PageTag</A></B></TD>
<TD>Define a scripting variable that exposes the requested page context
item as a scripting variable and a page scope bean.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="PageTei.html">PageTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>page</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ParameterTag.html">ParameterTag</A></B></TD>
<TD>Define a scripting variable based on the value(s) of the specified
parameter received with this request.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ParameterTei.html">ParameterTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>parameter</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ResourceTag.html">ResourceTag</A></B></TD>
<TD>Define a scripting variable based on the contents of the specified
web application resource.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ResourceTei.html">ResourceTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>resource</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="SizeTag.html">SizeTag</A></B></TD>
<TD>Define a scripting variable that will contain the number of elements
found in a specified array, Collection, or Map.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="SizeTei.html">SizeTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>size</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="StrutsTag.html">StrutsTag</A></B></TD>
<TD>Define a scripting variable that exposes the requested Struts
internal configuraton object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="StrutsTei.html">StrutsTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>struts</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="WriteTag.html">WriteTag</A></B></TD>
<TD>Tag that retrieves the specified property of the specified bean, converts
it to a String representation (if necessary), and writes it to the current
output stream, optionally filtering characters that are sensitive in HTML.</TD>
</TR>
</TABLE>
&nbsp;
<P>
<A NAME="package_description"><!-- --></A><H2>
Package org.apache.struts.taglib.bean Description
</H2>
<P>
The "struts-bean" tag library contains JSP custom tags useful in defining new
beans (in any desired scope) from a variety of possible sources, as well as a
tag to render a particular bean (or bean property) to the output response.
<br><br>
<a name="doc.Description"></a>
<div align="center">
<a href="#doc.Intro">[Introduction]</a>
<a href="#doc.Properties">[Bean Properties]</a>
<a href="#doc.Creation">[Bean Creation]</a>
<a href="#doc.Output">[Bean Output]</a>
</div>
<hr>
<a name="doc.Intro"></a>
<h3>Introduction</h3>
<p>Much of the power of JavaServer Pages (JSP) technology comes from the simple
and powerful mechanisms by which the servlet that is generated automatically
from your JSP source page can interact with JavaBeans that represent the
computational state of your application. In standard JSP pages, the
<code>&lt;jsp:useBean&gt;</code> tag is used create a bean (if necessary),
as well as a "scripting variable" that can be used within scriptlets to refer
to these beans.</p>
<p>The "struts-bean" tag library provides substantial enhancements to the
basic capability provided by <code>&lt;jsp:useBean&gt;</code>, as discussed
in the following sections:</p>
<ul>
<li><a href="#doc.Properties">Bean Properties</a> - Extended syntax to refer to
JavaBean properties with simple names (same as the standard JSP tags
<code>&lt;jsp:getProperty&gt;</code> and
<code>&lt;jsp:setProperty&gt;</code>), nested names (a property named
<code>address.city</code> returns the value retrieved by the Java
expression <code>getAddress().getCity()</code>), and indexed names
(a property named <code>address[3]</code> retrieves the fourth address
from the indexed "address" property of a bean).</li>
<li><a href="#doc.Creation">Bean Creation</a> - New JSP beans, in any scope,
can be created from a variety of objects and APIs associated with the
current request, or with the servlet container in which this page is
running.</li>
<li><a href="#doc.Output">Bean Output</a> - Supports the rendering of textual
output from a bean (or bean property), which will be included in the
response being created by your JSP page.</li>
</ul>
<p>See the <a href="../../../../../../struts-bean.html">Bean Tags
Reference</a> for detailed information about the available tags in this
tag library, and the valid attributes for each tag.</p>
<a name="doc.Properties"></a>
<h3>Bean Properties</h3>
<h5>Common Tag Attributes</h5>
<p>The tags in the "struts-bean" tag library (and, generally, in all tag
libraries included with the Struts framework) share a common set of tag
attributes that have the same meaning, no matter what tag they are used on.
These common attributes include:</p>
<ul>
<li><em>id</em> - Names the scripting variable that will be
created by this custom tag, as well as the key value used to locate this
bean in the scope defined by the <code>scope</code> attribute.</li>
<li><em>name</em> - Defines the key value by which an existing bean will be
looked up in the scope defined by the <code>scope</code> attribute
(if any), or by searching through the various scopes in the standard
order (page, request, session, application).</li>
<li><em>property</em> - Defines the name of a JavaBeans property, of the JSP
bean identified by the <code>name</code> and (optional) <code>scope</code>
attributes, whose value is to be used by this custom tag. If not
specified, the bean identified by <code>name</code> is itself used
as the value of interest. See below for more discussion about how a
property can be referenced.</li>
<li><em>scope</em> - Identifies the JSP scope ("page", "request", "session",
or "application" within which a particular bean will be searched for
(under the key specified by the <code>name</code> attribute) or created
(under the key specified by the <code>id</code> attribute). If not
specified, beans will generally be searched for in the order listed above,
or created in page scope.</li>
</ul>
<a name="doc.Properties.References"></a>
<h5>Property References</h5>
<p>Struts tags that support the <code>property</code> tag generally also
recognize a rich syntax for getting and setting properties. There are three
types of references supported: simple, nested, and indexed.</p>
<p><em>Simple References</em> - These are equivalent to the syntax you use with
the standard <code>&lt;jsp:getProperty&gt;</code> and
<code>&lt;jsp:setProperty&gt;</code> tags. A reference to a property named
"foo" is converted into a method call to <code>getFoo()</code> or
<code>setFoo(value)</code> (as appropriate), using the standard JavaBeans
Specification naming conventions for bean properties. Struts uses the
standard Java introspection APIs to identify the names of the actual property
getter and setter methods, so your beans can provided customized method names
through the use of a <code>BeanInfo</code> class. See the JavaBeans
Specification, available at <a href="http://java.sun.com/products/javabeans/">
http://java.sun.com/products/javabeans/</a>, for more information.</p>
<p><em>Nested References</em> - Nested references are used to access a
property through a hierarchy of property names separated by periods ("."),
similar to the way that nested properties are accessed in JavaScript. For
example, the following property reference in a getter (such as the
<code>&lt;bean:define&gt;</code> tag discussed below):</p>
<pre>
property="foo.bar.baz"
</pre>
<p>is translated into the equivalent the Java expression:</p>
<pre>
getFoo().getBar().getBaz()
</pre>
<p>If a nested reference is used in a setter (such as when an input form is
processed), the property setter is called on the <strong>last</strong> property
in the chain. For the above property reference, the equivalent Java
expression would be:</p>
<pre>
getFoo().getBar().setBaz(value)
</pre>
<p><em>Indexed References</em> - Subscripts can be used to access individual
elements of properties whose value is actually an array, or whose underlying
JavaBean offers indexed getter and setter methods. For example, the following
property reference in a getter (such as the <code>&lt;bean:define&gt;</code>
tag discussed below):</p>
<pre>
property="foo[2]"
</pre>
<p>is translated into the equivalent of the Java expression:</p>
<pre>
getFoo(2);
</pre>
<p>while the same property reference in a setter would call the
equivalent of:</p>
<pre>
setFoo(2, value)
</pre>
<p>As you can see from the above translations, the subscripts used in indexed
references are <strong>zero relative</strong> (that is, the first element in
an array is <code>foo[0]</code>), just as is true in the Java language.</p>
<p><em>Combined References</em> - Nesting and indexing can be combined in
arbitrary ways, so that expressions like <code>foo.bar[0].baz[2]</code> are
legal. You must be careful, of course, to ensure that the actual beans being
accessed by these references have properties of the appropriate names and
types. Otherwise, JSP runtime exceptions will be thrown.</p>
<p>See the JavaDocs for
<a href="../../util/PropertyUtils.html">PropertyUtils</a> for more detailed
information about the mechanisms that Struts uses to access
properties in a general way, through Java reflection APIs.</p>
<hr>
<a name="doc.Creation"></a>
<h3>Bean Creation</h3>
<h5>Introduction</h5>
<p>New beans can be created, and introduced into one of the four standard
JSP scopes (page, request, session, and application) through a variety of
techniques. The following subsections describe the use of the following
approaches:</p>
<ul>
<li>Java Code in Action Classes</li>
<li>Java Code in Scriptlets</li>
<li>The Standard <code>&lt;jsp:useBean&gt;</code> Tag</li>
<li>The Struts <code>&lt;bean:define&gt;</code> Tag</li>
<li>Other Struts Copying Tags</li>
</ul>
<h5>Java Code in Action Classes</h5>
<p>Because the JSP pages are compiled into Servlets, your <code>Action</code>
classes that are invoked by the Struts controller servlet have convenient
access to three of the four standard JSP scopes (request, session, and
application). It is very common practice for the business logic contained in
your <code>Action</code> class to create results that are stored in request
or session scope, which will be used by a JSP page you forward control to in
rendering the next page of the user interface.</p>
<p><em>Request Scope</em> - To store a bean in request scope under name "cust",
your <code>Action</code> class would execute code similar to this:</p>
<pre>
Customer customer = ... create or acquire a customer reference ...;
request.setAttribute("cust", customer);
</pre>
<p><em>Session Scope</em> - To store a bean in session scope under name "user"
(perhaps in a logon action), your <code>Action</code> class would execute code
similar to this:</p>
<pre>
User user = ... look up valid user in the database ...;
HttpSession session = request.getSession();
session.setAttribute("user", user);
</pre>
<p><em>Application Scope</em> - Generally, application scope beans are
initialized in the <code>init()</code> method of a startup servlet. However,
it is legal for an <code>Action</code> class to create such beans, if this is
appropriate, like this:</p>
<pre>
Foo foo = ... create a Foo ...;
servlet.getServletContext().setAttribute("foo", foo);
</pre>
<h5>Java Code in Scriptlets</h5>
<p>While it is not a recommended practice in Struts-based applications
(because developers will be tempted to mix business logic and presentation
logic in their JSP pages), it is legal for scriptlet code in a JSP page to
create new JavaBeans dynamically, and add them to any of the four possible
scopes, as demonstrated in the code examples below:</p>
<p><em>Page Scope</em> - To store a bean in page scope under name "foo",
your scriptlet must execute code like this:</p>
<pre>
&lt;%
Foo foo = ... create a foo ...;
pageContext.setAttribute("foo", foo, PageContext.PAGE_SCOPE);
%&gt;
</pre>
<p><em>Request Scope</em> - To store a bean in request scope under name "cust",
your scriplet must execute code like this:</p>
<pre>
&lt;%
Customer customer = ... create or acquire a customer reference ...;
pageContext.setAttribute("cust", customer, PageContext.REQUEST_SCOPE);
%&gt;
</pre>
<p><em>Session Scope</em> - To store a bean in session scope under name "user",
(perhaps as a result of a validated login), your scriplet must execute code
like this:</p>
<pre>
&lt;%
User user = ... look up valid user in the database ...;
pageContext.setAttribute("user", user, PageContext.SESSION_SCOPE);
%&gt;
</pre>
<p><em>Application Scope</em> - Generally, application scope beans are
initialized in the <code>init()</code> method of a startup servlet. However,
a scriptlet can create such beans, if appropriate, like this:</p>
<pre>
&lt;%
Foo foo = ... create a Foo ...;
pageContext.setAttribute("foo", foo, PageContext.APPLICATION_SCOPE);
%&gt;
</pre>
<p><strong>NOTE</strong> - As mentioned above, using scriptlets in your JSP
pages is strongly discouraged in a Struts based application, unless you are
executing code that is <strong>only</strong> related to presentation of
existing data. In general, your application's processing logic should be
encapsulated in <code>Action</code> classes (or in beans or EJBs called by
those classes), rather than being intermixed in your JSP pages.</p>
<h5>The Standard <code>&lt;jsp:useBean&gt;</code> Tag</h5>
<p>JavaServer Pages (JSP) offers a standard tag,
<code>&lt;jsp:useBean&gt;</code> that can be used to create a new bean, or
introduce a reference to an existing bean, into a JSP page. Beans (or bean
references) introduced through this mechanism are completely interoperable
with beans created by any of the Struts creation techniques described in this
section.</p>
<p>You <strong>must</strong> use <code>&lt;jsp:useBean&gt;</code> to introduce
a reference to an existing bean, if you wish to reference that bean with other
standard JSP tags (such as <code>&lt;jsp:getProperty&gt;</code> or
<code>&lt;jsp:setProperty&gt;</code>). If you only wish to reference such
beans with other Struts tags, use of <code>&lt;jsp:useBean&gt;</code> is not
required.</p>
<p>For more information about the <code>&lt;jsp:useBean&gt;</code> tag, see
the JavaServer Pages Specification, available at
<a href="http://java.sun.com/products/jsp/download.html">
http://java.sun.com/products/jsp/download.html</a>.</p>
<h5>The Struts <code>&lt;bean:define&gt;</code> Tag</h5>
<p>Struts provides a powerful, general purpose, tag
(<code>&lt;bean:define&gt;</code>) that can be used to create a new bean,
in any scope, by copying another bean (or the value of the property of
another bean). This tag supports the "property" attribute, and therefore
all the power of property references, as discused
<a href="#doc.Properties.References">above</a>. It can be used in a
variety of different ways, described further below. Unless you specify
the "toScope" attribute, all defined beans will be created in page scope.</p>
<p><em>Introduce A String Constant</em> - You can create a new bean that has
a constant String value (or the result of calculating a runtime expression):
</p>
<pre>
&lt;bean:define id="foo" value="This is a new String"/&gt;
&lt;bean:define id="bar" value='<%= "Hello, " + user.getName() %>'/&gt;
&lt;bean:define id="last" scope="session"
value='<%= request.getRequestURI() %>'/&gt;
</pre>
<p><em>Copy An Existing Bean</em> - You can create a new reference to an
existing bean object. You can specify the Java class or interface the new
bean is expected to conform to with the "type" attribute, or accept the
default type of <code>java.lang.Object</code> (this only affects the scripting
variable that is exposed to scriptlets, so it is not generally meaningful in
Struts-based applications).</p>
<pre>
&lt;bean:define id="foo" name="bar"/&gt;
&lt;bean:define id="baz" name="bop" type="com.mycompany.MyBopClass"/&gt;
</pre>
<p><em>Copy An Existing Bean Property</em> - You can create a new bean that
is initialized to the value returned by a property getter. The value of the
"property" attribute can be any simple, nested, or indexed property reference
that follows the rules described earlier. In the first example below, we
also illustrate accessing the property of a request scope bean, and creating
the new bean in session scope (rather than the default page scope).</p>
<pre>
&lt;bean:define id="foo" name="bar" property="baz" scope="request"
toScope="session"/&gt;
&lt;bean:define id="bop" name="user" property="role[3].name"/&gt;
</pre>
<h5>Other Struts Copying Tags</h5>
<p>Struts offers a variety of bean creation tags that copy existing beans (or
bean properties) from the environment within which this page is running, and
the request that is currently being processed. Not all of the attributes
for each tag are illustrated in the examples below - see the
<a href="../../../../../../struts-bean.html">Bean Tags Reference</a> for
more information. Any bean created by these tags exists only in page
scope, for the remainder of the current page.</p>
<p><em>Copy A Cookie</em> - You can create a new bean containing a
<code>javax.servlet.http.Cookie</code> that was included in the current
request. If no cookie of the specified name was included, a request time
expression will be thrown - therefore, it is common to nest the use of this
tag inside a <code>&lt;logic:present cookie="xxx"&gt;</code> tag to ensure
that the cookie was really included. If there is the possibility that more
than one cookie of the same name was included, specify the "multiple"
attribute (and the resulting bean will be an array of Cookies, instead of
a single Cookie).</p>
<pre>
&lt;bean:cookie id="foo" name="cookiename"/&gt;
&lt;bean:cookie id="all" name="JSESSIONID" multiple="true"/&gt;
</pre>
<p><em>Copy A Request Header</em> - You can create a new bean containing the
value of an HTTP header included in this request. If no header of the
specified name was included, a request time exception will be thrown -
therefore, it is common to nest the use of this tag inside a
<code>&lt;logic:present header="xxx"&gt;</code> tag to ensure that the header
was really included. If there is the possibility that more than one header
of the same name was included, specify the "multiple" attribute (and the
resulting value bean will be an array of String values, instead of a
single String).</p>
<pre>
&lt;bean:header id="agent" name="User-Agent"/&gt;
&lt;bean:header id="languages" name="Accept-Language" multiple="true"/&gt;
</pre>
<p><em>Copy A Dynamically Created Response</em> - You can generate an internal
request to the application you are running, and turn the response data that is
returned from that request into a bean (of type String). One possible use
for this technique is to acquire dynamically created XML formatted data that
will be stored in a bean and later manipulated (such as by applying an XSLT
stylesheet). If the current request is part of a session, the generated
request for the include will also include the session identifier (and thus be
considered part of the same session).</p>
<pre>
&lt;bean:include id="text" name="/generateXml?param1=a&param2=b"/&gt;
</pre>
<p><em>Copy A JSP Implicitly Defined Object</em> - You can create a bean that
is one of the JSP implicitly defined objects (see the JSP spec for more
details). This is useful if you wish to perform property getter actions
against the implicit object with a custom tag instead of a scriptlet.</p>
<pre>
&lt;bean:page id="app" property="application"/>
&lt;bean:page id="sess" property="session"/>
</pre>
<p><em>Copy A Request Parameter</em> - You can create a new bean containing the
value of a parameter included in this request. If no parameter of the
specified name was included, a request time exception will be thrown -
therefore, it is common to nest the use of this tag inside a
<code>&lt;logic:present parameter="xxx"&gt;</code> tag to ensure that the
parameter was really included. If there is the possibility that more than
one parameter of the same name was included, specify the "multiple" attribute
(and the resulting value bean will be an array of String values, instead of a
single String).</p>
<pre>
&lt;bean:parameter id="name" name="name"/&gt;
&lt;bean:header id="options" name="option" multiple="true"/&gt;
</pre>
<p><em>Copy a Web Application Resource</em> - You can create a new bean
containing either the value of a web application resource as a String, or
a <code>java.io.InputStream</code> for reading the content of that resource.
The resource is accessed with a context-relative path (beginning with "/"),
using the <code>ServletContext.getResource()</code> or
<code>ServletContext.getResourceAsStream()</code> methods on the underlying
application object.</p>
<pre>
&lt;bean:resource id="deployment" name="/WEB-INF/web.xml"/&gt;
&lt;bean:resource id="stream" name="/WEB-INF/web.xml"
input="true"/&gt;
</pre>
<p><em>Copy A Struts Configuration Object</em> - You can create a new bean
containing one of the standard Struts framework configuration objects. Doing
this gives you access to the properties of the configuration object, if needed.
</p>
<pre>
&lt;bean:struts id="form" formBean="CustomerForm"/&gt;
&lt;bean:struts id="fwd" forward="success"/&gt;
&lt;bean:struts id="map" mapping="/saveCustomer"/&gt;
</pre>
<hr>
<a name="doc.Output"></a>
<h3>Bean Output</h3>
<p>None of the Struts Bean tags discussed so far render any output to the
response page that is being generated from this JSP page. They are executed
in order to make relevant Java objects visible as beans for further
manipulation. The following tags cause output to be written to the response,
and therefore made visible to the ultimate requester.</p>
<p><em>Render An Internationalized Message</em> - You can specify a message
key (with optional parameter replacement objects) that are passed to a
<a href="../../util/MessageResources.html">MessageResources</a> object that
returns the corresponding message text. The message text will be copied to
the response currently being created. By default, messages are looked up in
the application resources bundle that is initialized for you (as an
application scope bean) by the Struts controller servlet, using the Locale
must recently stored in the user's session. These defaults can be overridden
by setting values for the "bundle" and "locale" attributes, as described in the
<a href="../../../../../../struts-bean.html#message">Bean Tags Reference</a>.
<pre>
&lt;bean:message key="label.Cancel"/&gt;
&lt;bean:message key="message.hello" arg0='<%= user.getFullName() %>'/&gt;
</pre>
<p><em>Render A Bean or Bean Property</em> - The contents of a bean, or bean
property, are converted to a String and then copied to the response currently
being created. This tag understands the syntax for simple, nested, and
indexed property references described <a href="#doc.Properties.Reference">
above</a>. Beans from any scope can be requested - by default, the scopes
are searched in expanding visibility order (page, request, session, and
application) to locate the requested bean.</p>
<pre>
&lt;bean:write name="username"/&gt;
&lt;bean:write name="user" property="fullName"/&gt;
&lt;bean:write name="customer" property="orders[2].partNumber"
scope="session"/&gt;
</pre>
<P>
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/html/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
Copyright © 2000-2001 - Apache Software Foundation
</BODY>
</HTML>