The link() method

This method acts as a wrapper to build a valid OpenCms URL for a given internal VFS resource. This allows you to set URLs without having to add the name of the web application and servlet context manually. Second, if a page is exported into a static HTML page by OpenCms, a URL returned by the   link() method will be replaced by it's static link target. The link method is also used to build the internal references for the link management.

Note: the  link() method cannot be used for external links to other domains!

Parameters:

Name Description
java.lang.String link The URI of the resource in the OpenCms VFS.

 

Example usage:

Build a valid URL for a resource in the current folder:

org.opencms.jsp.CmsJspActionElement cms = 
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);

out.println(cms.link("index.html"));

Build a valid URL for a resource in another folder:

org.opencms.jsp.CmsJspActionElement cms = 
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);

out.println(cms.link("/some/other/folder/index.html"));

Build a valid URL for a resource in the root folder:

org.opencms.jsp.CmsJspActionElement cms =
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);

out.println(cms.link("/index.html"));