The servlet bean SiteLinkDroplet can generate URLs that reference other sites. You can use this servlet bean to write page code that generates links to different sites and paths, depending on the current site context.

SiteLinkDroplet uses input parameters siteId and path to generate a URL as follows:

If input parameter...

Contains...

Then...

siteId

Site ID

Use production URL configured for this site.

siteId

(parameter omitted)

Use the current site.

path

Leading forward slash (/)

Replace old path with new path relative to site root.

path

No leading forward slash (/)

Make specified path relative to current page.

path

(parameter omitted)

Retain old path relative to site root.

The output parameter url contains the generated URL, which you can use to set a link to the desired site.

SiteLinkDroplet also provides the following optional input parameters:

  • queryParams: Appends the specified query parameters to the generated URL.

  • protocol: Specifies the protocol to use—http or https—in the generated URL. If omitted, the protocol is set from the SiteURLManager property defaultProtocol.

  • inInclude: If SiteLinkDroplet is invoked inside an included page, you can set inInclude to true in order to specify that the generated URL contains the included page’s path relative to the parent page.

The following examples demonstrate two use cases:

Site ID Specified, Path Omitted

In the following example, the following conditions apply:

<dsp:droplet name="SiteLinkDroplet">
  <dsp:param name="siteId" value="mySite"/>
  <dsp:oparam name="output">
    <dsp:getvalueof var="newUrl" param="url" vartype="java.lang.String">
      <dsp:a href="${newUrl}>">
        Click Here!</dsp:a>
    </dsp:getvalueof>
  </dsp:oparam>
</dsp:droplet>

This generates the following link:

<a href="http://SecondSite.com/dir/index.jsp">Click Here!</a>

Site ID Omitted, Path Replaced

If the current page is http://FirstSite.com/dir/index.jsp, the following code generates this link:

<a href="http://FirstSite.com/home/index.jsp">Click Here!</a>

<dsp:droplet name="SiteLinkDroplet">
  <dsp:param name="path" value="/home/index.jsp"/>
  <dsp:oparam name="output">
    <dsp:getvalueof var="url" param="url" vartype="java.lang.String">
      <dsp:a href="${url}">
        Click Here!</dsp:a>
    </dsp:getvalueof>
  </dsp:oparam>
</dsp:droplet>

Copyright © 1997, 2014 Oracle and/or its affiliates. All rights reserved. Legal Notices