# Creating URLs to Portal Resources

WebLogic Portal provides a convenient, extensible mechanism for creating URLs to your portal resources in a portal Web project that can transfer from domain to domain without breaking, especially when server names and port numbers change. This URL-creation mechanism also lets you switch between secure and non-secure URLs (http and https).

The two pieces involved in creating portable URLs are:

- The <render:*Url> JSP tags in the Portal Rendering JSP tag library.
- A portal Web project's WEB-INF/url-template-config.xml file.

The url-template-config.xml file contains multiple URL "templates," each with a unique name. Those template URLs contain variables such as url:domain and url:port that are read in from the active server. The <render:*Url> JSP tags have a "template" attribute in which you can specify the name of a URL template in url-template-config.xml.

The following examples show how the JSP tags use the templates to create URLs.

url-template-config.xml | <render:resourceUrl>
The following is a sample URL template in url-template-config.xml.
    <url-template name="secure-url">
        https://{url:domain}:{url:securePort}/{url:path}?{url:queryString}
    </url-template>
| The following is how the <render:resourceUrl> JSP tag would create a URL using the template.
    <% String reportpath = "reports/report1.html"; %>

    <a href="<render:resourceUrl template="secure-url" path="<%=reportpath%>"/>">
    View the Report
    </a>

You can use any of the URL templates in url-template-config.xml provided by WebLogic Portal, and you can add as many templates as you want to the file.

The following variables are available for use in URL template building:

{url:domain} - Reads the name of the server from the current request.

{url:port} - Reads the listen port number of the server from the current request. (See Troubleshooting below.)

{url:securePort} - Reads the SSL port number of the server from the current request. (See Troubleshooting below.)

{url:path} - Reads the name of the Web application. The URLs to all resources in a Web application are relative to the Web application directory.

{url:queryString} - Reads a queryString variable for the URL.

## Troubleshooting

If you are using a proxy server or switching back and forth between non-secure and secure ports, you may find that URLs do not resolve if you use the {url:port} or {url:securePort} variables. This is because the variables for those values are read from the request. For example, if a user in a non-secure port (port number 80) clicks a secure https link that was created with a URL template that uses the {url:securePort} variable, the port number of the request (80) is used for the {url:securePort} variable, which would create a secure request (https) on an non-secure port. The same could happen if a user on a proxy server (port 80) clicks a link to a resource outside the proxy server (port 443).

In both of those cases, you need to hard code port numbers in the URL templates to get URLs to resolve correctly.

## Web Services for Remote Portlets (WSRP)

The url-template-config.xml file automatically created in a portal Web project also contains URL templates and variables for WSRP portlets. These templates must remain in the file if you are going to be a WSRP producer.

Related Topics

Portal Rendering JSP Tags