Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.
NOTE: The
id
attribute is deprecated in Struts 2.1.x, and has been replaced by thevar
attribute.
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., &). 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
orget
, 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 likehttp://<host>:<port>/<context>/editUser.action?id=3333&name=John
the generated url will behttp://<host>:<port>/<context>/editUser.action?id=22&name=John
because the parameter defined in theparam
tag will take precedence
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.
NOTE: As of Struts 2.1.3 the includeParams constant defaults to
none
.
{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/url-description.html %}
{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/url-attributes.html %}
NOTE: When the
var
attribute is used with theurl
tag, the tag's generated URL value will be placed into the request scope in addition to the action scope.
<!-- 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>