This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • url
Skip to end of metadata
Go to start of metadata

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

The id attribute is deprecated in Struts 2.1.x, and has been replaced by the var attribute.

Description

This tag is used to create a URL.

You can use the <param> tag inside the body to provide additional request parameters. If the value of a param is an Array or an Iterable all the values will be added to the URL.

NOTE:

By default request parameters will be separated using escaped ampersands (i.e., &amp. This is necessary for XHTML compliance, however, when using the URL generated by this tag with the <s:property> tag, the escapeAmp attribute should be used to disable ampersand escaping.

NOTE:

When includeParams is 'all' or 'get', the parameter defined in a <param> tag will take precedence over any params included due to the includeParams attribute. For example, in Example 3 below, if there is a id parameter in the url where the page this tag is included like http://<host>:<port>/<context>/editUser.action?id=3333&name=John the generated url will be http://<host>:<port>/<context>/editUser.action?id=22&name=John because the parameter defined in the param tag will take precedence.

Setting a default value for includeParams

The property struts.url.includeParams can be used to set the default value of the includeParams attribute.

Setting the default value of includeParams
<struts>
   ...
   <constant name="struts.url.includeParams" value="none" />
   ...
</struts>

See Constant Configuration for further information.

As of Struts 2.1.3 the includeParams constant defaults to "none".

Parameters

Dynamic Attributes Allowed:

false
 

Name

Required

Default

Evaluated

Type

Description

action false false String The action to generate the URL for, if not using value
anchor false false String The anchor for this URL
encode false true false Boolean Whether to encode parameters
escapeAmp false true false Boolean Specifies whether to escape ampersand (&) to (&amp or not
forceAddSchemeHostAndPort false false false Boolean Specifies whether to force the addition of scheme, host and port or not
includeContext false true false Boolean Whether actual context should be included in URL
includeParams false none false String The includeParams attribute may have the value 'none', 'get' or 'all'
method false false String The method of action to use
namespace false false String The namespace to use
portletMode false false String The resulting portlet mode
portletUrlType false false String Specifies if this should be a portlet render or action URL. Default is "render". To create an action URL, use "action".
scheme false false String Set scheme attribute
value false false String The target value to use, if not using action
var false false String Name used to reference the value pushed into the Value Stack
windowState false false String The resulting portlet window state

Examples

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'

<-- Example 1 -->
<s:url value="editGadget.action">
    <s:param name="id" value="%{selected}" />
</s:url>

<-- Example 2 -->
<s:url action="editGadget">
    <s:param name="id" value="%{selected}" />
</s:url>

<-- Example 3-->
<s:url includeParams="get">
    <s:param name="id" value="%{'22'}" />
</s:url>

  • No labels

4 Comments

  1. Change "overriden" to "overridden".
    Change "exists" to "exist".
    Change the two URLs under "Description" to valid URLs.
    Change "cause" to "because".
    Change "he action generate url for, if not using value" to "The action to generate url for, if not using value".
    Change "&lt" to <" in the last code sample.

  2. To the description of the "method" parameter ("The method of action to use"), add the following:

    the "action" parameter must also be present in order for the "method" parameter to work, even if the url points to the same action as the current one.

  3. Both in the "Description" and "Parameters" sections, the final 'semi-column'+'right-parenthesis' after '&amp' are mistakenly parsed (by the wiki engine I guess) as an emoticon. Moreover, it looks like the corresponding image is not available. A quick workaround would be to add a space between the semi-column and the right parenthesis.

  4. Please add to the description for includeContext:

    The value attribute is required when using the includeContext attribute.

    If the action & value attributes are omitted, the context will be included regardless of the settings in includeContext.