类 LinkTool
- 所有已实现的接口:
Serializable,Cloneable
The LinkTool provides many methods to work with URIs and can help you:
- construct full URIs (absolute or relative)
- encode session ID into a URI
- retrieve server, port and path info for the current request
- reconstruct or alter the current request URI
- and more..
The LinkTool is somewhat special in that nearly all public methods return a new instance of LinkTool. This facilitates greatly the repeated use of the LinkTool in Velocity and leads to an elegant syntax.
Template example(s):
#set( $base = $link.path('MyPage.vm').anchor('view') )
<a href="$base.param('select','this')">this</a>
<a href="$base.param('select','that')">that</a>
Toolbox configuration:
<tools>
<toolbox scope="request">
<tool class="org.apache.velocity.tools.view.LinkTool"
forceRelative="true" includeRequestParams="true"/>
</toolbox>
</tools>
This tool may only be used in the request scope.
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Id$
- 作者:
- Gabe Sidler, Nathan Bubna, Chris Schultz
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明static final Stringprotected booleanprotected jakarta.servlet.http.HttpServletRequestprotected jakarta.servlet.http.HttpServletResponse从类继承的字段 org.apache.velocity.tools.generic.LinkTool
APPEND_PARAMS_KEY, appendParams, charset, CHARSET_KEY, DEFAULT_CHARSET, DEFAULT_SCHEME, FORCE_RELATIVE_KEY, forceRelative, fragment, FRAGMENT_KEY, host, HOST_KEY, HTML_QUERY_DELIMITER, opaque, path, PATH_KEY, port, PORT_KEY, query, QUERY_KEY, queryDelim, scheme, SCHEME_KEY, SECURE_SCHEME, self, URI_KEY, user, USER_KEY, XHTML_MODE_KEY, XHTML_QUERY_DELIMITER从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明addMissingRequestParams(Object... ignoreThese) Adds all of the current request's parameters to this link's "query data" except for those whose keys match any of the specified strings or already have a value set for them in the current instance.addRequestParams(Object... butOnlyThese) Adds the specified parameters (if they exist) from the current request to the query data of a copy of this instance.addRequestParamsExcept(Object... ignoreThese) Adds all of the current request's parameters to this link's "query data" except for those whose keys match any of the specified strings.protected voidconfigure(ValueParser props) Initially, this returns the context path that addresses this web application, e.g.Returns a URL that addresses the web application.Initially, this retrieves the path for the current request regardless of whether this is a direct request or an include by the RequestDispatcher.protected booleanprotected voidsetFromRequest(jakarta.servlet.http.HttpServletRequest request) voidsetIncludeRequestParams(boolean includeRequestParams) Controls whether or not this tool starts off with all parameters from the last request automatically.toString()Overrides to use response.encodeURL to get session id into URL if sessions are used but cookies are not supported.从类继承的方法 org.apache.velocity.tools.generic.LinkTool
absolute, absolute, anchor, append, append, appendAsArray, appendPath, appendQuery, combinePath, combineQuery, createURI, decode, decodeQueryPercents, directory, duplicate, duplicate, encode, equals, getAnchor, getAppendParams, getBaseRef, getCharacterEncoding, getDirectory, getFile, getHost, getParams, getPath, getPort, getQuery, getRoot, getScheme, getSelf, getUri, getUser, handleParamsBoolean, hashCode, host, insecure, isAbsolute, isOpaque, isRelative, isSecure, isXHTML, normalizeQuery, param, params, parseQuery, parseQuery, path, port, query, relative, relative, remove, removeParam, root, scheme, secure, set, setAppendParams, setCharacterEncoding, setForceRelative, setFragment, setFromURI, setHost, setParam, setParams, setPath, setPort, setQuery, setScheme, setUserInfo, setXHTML, toQuery, toQuery, toURI, uri, user从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
INCLUDE_REQUEST_PARAMS_KEY
- 另请参阅:
-
request
protected jakarta.servlet.http.HttpServletRequest request -
response
protected jakarta.servlet.http.HttpServletResponse response -
includeRequestParams
protected boolean includeRequestParams
-
-
构造器详细资料
-
LinkTool
public LinkTool()
-
-
方法详细资料
-
configure
-
setFromRequest
protected void setFromRequest(jakarta.servlet.http.HttpServletRequest request) -
setIncludeRequestParams
public void setIncludeRequestParams(boolean includeRequestParams) Controls whether or not this tool starts off with all parameters from the last request automatically. Default is false.
- 参数:
includeRequestParams- whether or not to keep current request params
-
addRequestParams
Adds the specified parameters (if they exist) from the current request to the query data of a copy of this instance. If no parameters are specified, then all of the current request's parameters will be added.- 参数:
butOnlyThese- curent request parameters to keep- 返回:
- A LinkTool object with the specified parameters from the current request added to it or all the params if none specified.
-
addRequestParamsExcept
Adds all of the current request's parameters to this link's "query data" except for those whose keys match any of the specified strings.- 参数:
ignoreThese- curent request parameters to ignore- 返回:
- A LinkTool object with all of the current request's parameters added to it, except those specified.
-
addMissingRequestParams
Adds all of the current request's parameters to this link's "query data" except for those whose keys match any of the specified strings or already have a value set for them in the current instance.- 参数:
ignoreThese- curent request parameters to ignore- 返回:
- A LinkTool object with all of the current request's parameters added to it, except those specified or those that already have values.
-
isPathChanged
protected boolean isPathChanged() -
getContextPath
Initially, this returns the context path that addresses this web application, e.g.
/myapp. This string starts with a "/" but does not end with a "/". If the path has been changed (e.g. via a call toLinkTool.path(Object)), then this will simply be the first "directory" in the path (i.e. everything from the start up to the second backslash).- 覆盖:
getContextPath在类中LinkTool- 返回:
- context path
- 另请参阅:
-
getRequestPath
Initially, this retrieves the path for the current request regardless of whether this is a direct request or an include by the RequestDispatcher. This string should always start with a "/". If the path has been changed (e.g. via a call to
LinkTool.path(Object)), then this will simply be everything in the path after thegetContextPath()(i.e. the second "/" in the path and everything after).- 返回:
- request path
-
getContextURL
Returns a URL that addresses the web application. (e.g.
http://myserver.net/myapp/. This essentially just replaces the full path with thegetContextPath()and removes the anchor and query data.- 返回:
- context URL
-
toString
Overrides to use response.encodeURL to get session id into URL if sessions are used but cookies are not supported.
-