类 UrlTag
- java.lang.Object
- javax.servlet.jsp.tagext.TagSupport
- org.springframework.web.servlet.tags.RequestContextAwareTag
- org.springframework.web.servlet.tags.HtmlEscapingAwareTag
- org.springframework.web.servlet.tags.UrlTag
- 所有已实现的接口:
Serializable
,IterationTag
,JspTag
,Tag
,TryCatchFinally
,ParamAware
public class UrlTag extends HtmlEscapingAwareTag implements ParamAware
The<url>
tag creates URLs. Modeled after the JSTLc:url
tag with backwards compatibility in mind.Enhancements to the JSTL functionality include:
- URL encoded template URI variables
- HTML/XML escaping of URLs
- JavaScript escaping of URLs
Template URI variables are indicated in the
'value'
attribute and marked by braces '{variableName}'. The braces and attribute name are replaced by the URL encoded value of a parameter defined with the spring:param tag in the body of the url tag. If no parameter is available the literal value is passed through. Params matched to template variables will not be added to the query string.Use of the spring:param tag for URI template variables is strongly recommended over direct EL substitution as the values are URL encoded. Failure to properly encode URL can leave an application vulnerable to XSS and other injection attacks.
URLs can be HTML/XML escaped by setting the
'htmlEscape'
attribute to 'true'. Detects an HTML escaping setting, either on this tag instance, the page level, or theweb.xml
level. The default is 'false'. When setting the URL value into a variable, escaping is not recommended.Example usage:
<spring:url value="/url/path/{variableName}"> <spring:param name="variableName" value="more than JSTL c:url" /> </spring:url>
The above results in:
/currentApplicationContext/url/path/more%20than%20JSTL%20c%3Aurl
Attribute Summary Attribute Required? Runtime Expression? Description value true true The URL to build. This value can include template {placeholders} that are replaced with the URL encoded value of the named parameter. Parameters must be defined using the param tag inside the body of this tag. context false true Specifies a remote application context path. The default is the current application context path. var false true The name of the variable to export the URL value to. If not specified the URL is written as output. scope false true The scope for the var. 'application', 'session', 'request' and 'page' scopes are supported. Defaults to page scope. This attribute has no effect unless the var attribute is also defined. htmlEscape false true Set HTML escaping for this tag, as a boolean value. Overrides the default HTML escaping setting for the current page. javaScriptEscape false true Set JavaScript escaping for this tag, as a boolean value. Default is false.
字段概要
从类继承的字段 org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE
从类继承的字段 javax.servlet.jsp.tagext.TagSupport
id, pageContext
从接口继承的字段 javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
从接口继承的字段 javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
构造器概要
构造器 构造器 说明 UrlTag()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addParam(Param param)
Callback hook for nested spring:param tags to pass their value to the parent tag.protected String
createQueryString(List<Param> params, Set<String> usedParams, boolean includeQueryStringDelimiter)
Build the query string from available parameters that have not already been applied as template params.int
doEndTag()
int
doStartTagInternal()
Called by doStartTag to perform the actual work.protected String
replaceUriTemplateParams(String uri, List<Param> params, Set<String> usedParams)
Replace template markers in the URL matching available parameters.void
setContext(String context)
Set the context path for the URL.void
setJavaScriptEscape(boolean javaScriptEscape)
Set JavaScript escaping for this tag, as boolean value.void
setScope(String scope)
Set the scope to export the URL variable to.void
setValue(String value)
Set the value of the URL.void
setVar(String var)
Set the variable name to expose the URL under.从类继承的方法 org.springframework.web.servlet.tags.HtmlEscapingAwareTag
htmlEscape, isDefaultHtmlEscape, isHtmlEscape, isResponseEncodedHtmlEscape, setHtmlEscape
从类继承的方法 org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doFinally, doStartTag, getRequestContext
从类继承的方法 javax.servlet.jsp.tagext.TagSupport
doAfterBody, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
构造器详细资料
UrlTag
public UrlTag()
方法详细资料
setContext
public void setContext(String context)
Set the context path for the URL. Defaults to the current context.
setVar
public void setVar(String var)
Set the variable name to expose the URL under. Defaults to rendering the URL to the current JspWriter
setScope
public void setScope(String scope)
Set the scope to export the URL variable to. This attribute has no meaning unless var is also defined.
setJavaScriptEscape
public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException
Set JavaScript escaping for this tag, as boolean value. Default is "false".- 抛出:
JspException
addParam
public void addParam(Param param)
从接口复制的说明:ParamAware
Callback hook for nested spring:param tags to pass their value to the parent tag.- 指定者:
addParam
在接口中ParamAware
- 参数:
param
- the result of the nestedspring:param
tag
doStartTagInternal
public int doStartTagInternal() throws JspException
从类复制的说明:RequestContextAwareTag
Called by doStartTag to perform the actual work.- 指定者:
doStartTagInternal
在类中RequestContextAwareTag
- 返回:
- same as TagSupport.doStartTag
- 抛出:
JspException
- 另请参阅:
TagSupport.doStartTag()
doEndTag
public int doEndTag() throws JspException
- 指定者:
doEndTag
在接口中Tag
- 覆盖:
doEndTag
在类中TagSupport
- 抛出:
JspException
createQueryString
protected String createQueryString(List<Param> params, Set<String> usedParams, boolean includeQueryStringDelimiter) throws JspException
Build the query string from available parameters that have not already been applied as template params.The names and values of parameters are URL encoded.
- 参数:
params
- the parameters to build the query string fromusedParams
- set of parameter names that have been applied as template paramsincludeQueryStringDelimiter
- true if the query string should start with a '?' instead of '&'- 返回:
- the query string
- 抛出:
JspException
replaceUriTemplateParams
protected String replaceUriTemplateParams(String uri, List<Param> params, Set<String> usedParams) throws JspException
Replace template markers in the URL matching available parameters. The name of matched parameters are added to the used parameters set.Parameter values are URL encoded.
- 参数:
uri
- the URL with template parameters to replaceparams
- parameters used to replace template markersusedParams
- set of template parameter names that have been replaced- 返回:
- the URL with template parameters replaced
- 抛出:
JspException