类 LinkTool

所有已实现的接口:
Cloneable
直接已知子类:
LinkTool, SecureLinkTool, StrutsLinkTool

public class LinkTool extends LinkTool

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: LinkTool.java 749726 2009-03-03 20:19:15Z nbubna $
作者:
Gabe Sidler, Nathan Bubna, Chris Schultz
  • 字段详细资料

    • INCLUDE_REQUEST_PARAMS_KEY

      public static final String INCLUDE_REQUEST_PARAMS_KEY
      另请参阅:
    • request

      protected HttpServletRequest request
    • response

      protected HttpServletResponse response
    • includeRequestParams

      protected boolean includeRequestParams
  • 构造器详细资料

    • LinkTool

      public LinkTool()
  • 方法详细资料

    • configure

      protected void configure(ValueParser props)
      从类复制的说明: SafeConfig
      Does the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.
      覆盖:
      configure 在类中 LinkTool
    • setFromRequest

      protected void setFromRequest(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.

    • addRequestParams

      public LinkTool addRequestParams(String... butOnlyThese)
      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.
      返回:
      A LinkTool object with the specified parameters from the current request added to it or all the params if none specified.
    • addRequestParamsExcept

      public LinkTool addRequestParamsExcept(String... 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.
      返回:
      A LinkTool object with all of the current request's parameters added to it, except those specified.
    • addMissingRequestParams

      public LinkTool addMissingRequestParams(String... 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.
      返回:
      A LinkTool object with all of the current request's parameters added to it, except those specified or those that already have values.
    • addRequestParams

      private LinkTool addRequestParams(boolean ignore, String... special)
    • contains

      private boolean contains(String[] set, String name)
    • isPathChanged

      protected boolean isPathChanged()
    • getContextPath

      public String 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 to LinkTool.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
      另请参阅:
    • getRequestPath

      public String 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 the getContextPath() (i.e. the second "/" in the path and everything after).

    • getContextURL

      public String getContextURL()

      Returns a URL that addresses the web application. (e.g. http://myserver.net/myapp/. This essentially just replaces the full path with the getContextPath() and removes the anchor and query data.

    • toString

      public String toString()
      Overrides to use response.encodeURL to get session id into URL if sessions are used but cookies are not supported.
      覆盖:
      toString 在类中 LinkTool