Class URL
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' 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.
- action (String) - (value or action choose either one, if both exist value takes precedence) action's name (alias)
- value (String) - (value or action choose either one, if both exist value takes precedence) the url itself
- scheme (String) - http scheme (http, https) defaults to the scheme this request is in
- namespace - action's namespace
- method (String) - action's method name, defaults to 'execute'
- encode (Boolean) - url encode the generated url. Defaults to 'true'.
- includeParams (String) - The includeParams attribute may have the value 'none', 'get' or 'all'. Defaults to 'none'. none - include no parameters in the URL (default) get - include only GET parameters in the URL all - include both GET and POST parameters in the URL
- includeContext (Boolean) - Specifies whether to include the web app context path. Defaults to 'true'.
- escapeAmp (Boolean) - Specifies whether to escape ampersand (&) to (&) or not. Defaults to 'true'.
- portletMode (String) - The resulting portlet mode.
- windowState (String) - The resulting portlet window state.
- portletUrlType (String) - Specifies if this should be a portlet render or action URL.
- forceAddSchemeHostAndPort (Boolean) - Specifies whether to force the addition of scheme, host and port or not.
Examples
<-- 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>
- See Also:
-
Field Summary
Fields inherited from class org.apache.struts2.components.ContextBean
varFields inherited from class org.apache.struts2.components.Component
actionMapper, attributes, COMPONENT_STACK, devMode, escapeHtmlBody, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure -
Constructor Summary
ConstructorsConstructorDescriptionURL(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) -
Method Summary
Modifier and TypeMethodDescriptionbooleanCallback for the end tag of this component.findString(String expr) Evaluates the OGNL stack to find a String value.voidvoidvoidsetEncode(boolean encode) voidsetEscapeAmp(boolean escapeAmp) voidvoidsetForceAddSchemeHostAndPort(boolean forceAddSchemeHostAndPort) voidsetIncludeContext(boolean includeContext) voidsetIncludeParams(String includeParams) voidvoidsetNamespace(String namespace) voidsetPortletMode(String portletMode) voidsetPortletUrlType(String portletUrlType) voidvoidsetUrlIncludeParams(String urlIncludeParams) voidsetUrlRenderer(UrlRenderer urlRenderer) voidvoidsetWindowState(String windowState) booleanCallback for the start tag of this component.Methods inherited from class org.apache.struts2.components.ContextBean
getVar, putInContext, setVarMethods inherited from class org.apache.struts2.components.Component
addAllAttributes, addParameter, completeExpression, copyAttributes, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, stripExpression, toString, usesBody
-
Constructor Details
-
URL
public URL(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)
-
-
Method Details
-
setUrlIncludeParams
-
setUrlRenderer
-
setExtraParameterProvider
-
start
Description copied from class:ComponentCallback for the start tag of this component. Should the body be evaluated? -
end
Description copied from class:ComponentCallback for the end tag of this component. Should the body be evaluated again?
NOTE: will pop component stack. -
findString
Description copied from class:ComponentEvaluates the OGNL stack to find a String value.- Overrides:
findStringin classComponent- Parameters:
expr- OGNL expression.- Returns:
- the String value found.
-
getUrlProvider
-
setIncludeParams
-
setScheme
-
setValue
-
setAction
-
setNamespace
-
setMethod
-
setEncode
public void setEncode(boolean encode) -
setIncludeContext
public void setIncludeContext(boolean includeContext) -
setPortletMode
-
setWindowState
-
setPortletUrlType
-
setAnchor
-
setEscapeAmp
public void setEscapeAmp(boolean escapeAmp) -
setForceAddSchemeHostAndPort
public void setForceAddSchemeHostAndPort(boolean forceAddSchemeHostAndPort)
-