📄 package-summary.html
字号:
<h4><a name="doc.Other.hyperlinking">Maintaining Hyperlinks</a>
</h4>
<ul>
<li><a href="../../../../../../userGuide/struts-html.html#base">base</a>
</li>
</ul>
<p>When implementing a Web application, it is usually a good idea to use relative
references to other files in the same application. But in a dynamic application,
the controller servlet often returns a completely different file than the
one requested. (Often, the requested "file" doesn't actually exist, but
represents an action for the controller to interpret.) Since relative references
are resolved by the browser, they often won't work in a dynamic application.</p>
<p>To accommodate this, the Struts-HTML taglib provides a <code><base></code>
tag that renders an HTML element with an href attribute pointing
to the absolute location of its page. </p>
<p>As a rule, you should place the Struts-HTML base tag in the <head>
section of any JSP that uses relative references to other files.</p>
<pre> <head><br> <html:base/><br> </head><br></pre>
<h4><a name="doc.Other.sessions">Session Tracking</a>
</h4>
<p>The Java Servlet framework has built-in support for tracking a client through
a session. Sessions are a useful way to compensate for the stateless nature
of HTTP. Tracking a client can be done with either cookies or URL rewriting,
cookies being preferred when available. Struts offers three tags that make
it easy to write "session-aware" hyperlink references:</p>
<ul>
<li><a href="../../../../../../userGuide/struts-html.html#link">link</a>
- Renders an HTML anchor or hyperlink.</li>
<li><a href="../../../../../../userGuide/struts-html.html#rewrite">rewrite</a>
- Renders a request URI, but without creating the <a> hyperlink.
This tag is useful when you want to generate a string constant for use
by a JavaScript procedure.</li>
<li><a href="../../../../../../userGuide/struts-html.html#img">img</a>
- Renders an HTML <img> element with the image at the specified
URL.</li>
</ul>
<p>Each of these tags will automatically apply URL rewriting, to maintain
session state in the absence of cookies. The content displayed for the hyperlink
will be taken from the body of the tag. The base URL for the hyperlink
is calculated based on properties given with the tag.</p>
<p>Normally, the hyperlink or URI you specify is left unchanged. If you would
like to include dynamic parameters to the hyperlink or URI, you can pass
those to the tags via a JavaBean. If there may be naming conflicts, you
can also specify the scope that the tag searches (request, page, session,
application). </p>
<p>To pass a single dynamic parameter, specify the parameter's name using
the <code>paramId</code> attribute. You can then specify the name of the
JavaBean holding the value using the <code>paramName</code> attribute, and
a particular property using <code>paramProperty</code>. </p>
<p>So, a tag like</p>
<pre> <html:link paramId="target"<br> paramName="linkParams" <br> paramProperty="target"<br> paramScope="request"<br> >detail.html</html:link></pre>
<p>would correspond to something like</p>
<pre> <A HREF="detail.html?<%= <br> request.getAttribute("linkParams").getTarget()<br> %>"></A><br></pre>
<p>To search all scopes (request, page, session, and application), omit <code>
paramScope</code>. </p>
<p>The <code>paramProperty</code> attribute may also be omitted, so long as
the named bean identifies a value that can be converted to a String. </p>
<p>To pass multiple dynamic parameters, you can store them in a <code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
java.util.Map</a>
</code>, and use the name of the map for the <code>paramName</code>. The
map must then contain one or more <code>paramIds</code> and their corresponding
values. As the Map is processed, the keys are assumed to be the names of
query parameters to be appended. The value associated with each key must
be either a String or a String array representing the parameter value(s).
If a String array is specified, more than one value for the same query parameter
name will be created. </p>
<p>The HTML session tracking tags use several common attributes, that can
be organized into three groups, as follows. All of these attributes are
not used by all three tags (<code>link</code>, <code>rewrite</code>, and
<code>img</code>), and so the tags using each attribute is given. </p>
<p>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">forward, href, and page</th>
</tr>
<tr>
<td> forward </td>
<td> [ link rewrite ] - Logical name of a global ActionForward that
contains the actual content-relative URI of the destination of this
transfer. This hyperlink may be dynamically modified by the inclusion
of query parameters, as described in the tag description. You must specify
exactly one of the forward attribute, the href attribute, the linkName
attribute, or the page attribute </td>
</tr>
<tr>
<td> href </td>
<td> [ link rewrite ] - The URL to which this hyperlink will transfer
control if activated. This hyperlink may be dynamically modified by
the inclusion of query parameters, as described in the tag description.
You must specify exactly one of the forward attribute, the href attribute,
the linkName attribute, or the page attribute. </td>
</tr>
<tr>
<td> page </td>
<td> [ link rewrite ] - The context-relative path, starting with a
slash, of the image to be displayed by this tag. The rendered URL
for this image will automatically prepend the context path of this
web application (in the same manner as the page attribute on the link
tag works), in addition to any necessary URL rewriting. You must specify
either the page attribute or the src attribute. </td>
</tr>
</tbody>
</table>
</p>
<p>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">linkName, Target , and src</th>
</tr>
<tr>
<td> linkName </td>
<td>
<p>[ link ] - The anchor name to be defined within this page, so that
you can reference it with intra-page hyperlinks. In other words, the
value specified here will render a "name" element in the generated
anchor tag. </p>
</td>
</tr>
<tr>
<td> target </td>
<td> [ link img ] - The window target in which the resource requested
by this hyperlink will be displayed, for example in a framed presentation.
</td>
</tr>
<tr>
<td> src </td>
<td> [ img ] - The URL to which this image will be transferred from
This image may be dynamically modified by the inclusion of query parameters,
as described in the tag description. This value will be used unmodified
(other than potential URL rewriting) as the value of the "src" attribute
in the rendered tag. You must specify either the page attribute or the
the src attribute. </td>
</tr>
</tbody>
</table>
</p>
<p>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">paramId, paramName, paramProperty, paramScope </th>
</tr>
<tr>
<td> paramId </td>
<td> [ link img ] - The name of the request parameter that will be
dynamically added to the generated src URL. The corresponding value
is defined by the paramName and (optional) paramProperty attributes,
optionally scoped by the paramScope attribute</td>
</tr>
<tr>
<td> paramName </td>
<td> [ link img ] - The name of a JSP bean that is a String containing
the value for the request parameter named by paramId (if paramProperty
is not specified), or a JSP bean whose property getter is called to
return a String (if paramProperty is specified). The JSP bean is constrained
to the bean scope specified by the paramScope property, if it is specified.
</td>
</tr>
<tr>
<td> paramProperty </td>
<td> [ link img ] - The name of a property of the bean specified by
the paramName attribute, whose return value must be a String containing
the value of the request parameter (named by the paramId attribute)
that will be dynamically added to this hyperlink or src URL</td>
</tr>
<tr>
<td> paramScope </td>
<td> [ link img ] - The scope within which to search for the bean specified
by the paramName attribute. If not specified, all scopes are searched.
</td>
</tr>
</tbody>
</table>
</p>
<p>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">
<p>name, property, scope </p>
</th>
</tr>
<tr>
<td> name </td>
<td> [ link rewrite img ] - The name of a JSP bean that contains a
<code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
Map</a>
</code> representing the query parameters (if <code>property</code>
is not specified), or a JSP bean whose property getter is called
to return a <code>Map</code> (if <code>property</code> is specified).
</td>
</tr>
<tr>
<td> property </td>
<td>[ link rewrite img ] - The name of a property of the bean specified
by the name attribute, whose return value must be a <code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
Map</a>
</code> containing the query parameters to be added to the src
URL. You <b>must</b> specify the name attribute if you specify this
attribute </td>
</tr>
<tr>
<td> scope </td>
<td> [ link rewrite img ] - The scope within which to search for the
bean specified by the name attribute. If not specified, all scopes are
searched. </td>
</tr>
</tbody>
</table>
</p>
<p>See the <a href="../../../../../../userGuide/struts-html.html">HTML Tags Reference</a>
for the complete list of valid attributes for each tag.. </p>
<h4><a name="doc.Other.i18n">Internationalization</a>
</h4>
<p>Internationalization is automatically supported by the HTML tags where
appropriate. </p>
<p><a href="../../../../../../userGuide/struts-html.html#errors">Errors</a>
- By default, the text for your messages will be returned by the default
message resource, which will select the appropriate language for the user.
You may also specify another message resource using the <code>bundle</code>
attribute.</p>
<p><a href="../../../../../../userGuide/struts-html.html#html">HTML</a>
- Renders an HTML element with language attributes extracted from the
user's current Locale object, if there is one. </p>
<p><a href="../../../../../../userGuide/struts-html.html#image">image</a>
and <a href="../../../../../../userGuide/struts-html.html#img">img</a>
- Can optionally retrieve the value for its binary source and alt text
from the message resource, so that different images and/or text can be provided
for different locales. See the tag's <code>altKey</code>, <code> srcKey</code>
, and <code>bundle</code> attributes in the <a href="../../../../../../userGuide/struts-html.html">
HTML Tags Reference</a>
.</p>
<p><a href="../../../../../../userGuide/struts-html.html#messages">Messages</a>
- By default, the text for your messages will be returned by the default
message resource, which will select the appropriate language for the user.
You may also specify another message resource using the <code>bundle</code>
attribute.</p>
<p>See the <a href="../../../../../../userGuide/building_view.html#i18n">
Users Guide</a>
for more on how Struts helps you internationalize your applications.</p>
<p> </p>
<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> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../org/apache/struts/taglib/bean/package-summary.html"><B>PREV PACKAGE</B></A>
<A HREF="../../../../../org/apache/struts/taglib/logic/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>
<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -