4. JSP Aliases

PROBLEM

There are several places in a project where you may reference a JSP page. Rather than hard-coding references to the JSP pages, their needs to be a mechanism for defining aliases to the JSP pages.

SOLUTION

Directly referencing Java Server Pages (JSP) can be difficult for team-based development or add maintenance complexity to larger projects. The JSP Aliases configuration (under the Web Application tab of the Project Editor) provides a way to alias pages so that references to the JSP pages aren't hard-coded in Web Controllers or Components.

The URL (Alias) is the alias used to reference the view resource.

HOW IT WORKS

URL Mappings are used to associate URLs to Actions and Views. There are essentially two configuration options for Views. You can specify the views in the URL Mapping, or you can reference a variable that will contain the View. In both case there it is benefit to using JSP Aliases, particularly if a View is used for more than one URL Mapping or a View is specified in application logic (i.e. Action).

In the case where a View is used in more than one URL Mapping, a JSP alias can be configured to create an alias to a JSP, and the URL Mapping would specify the alias instead. If the at some point in time the actual JSP would change, it would only need to be modified in the JSP Alias. All URL Mappings that reference the JSP alias would automatically be reconfigured. A developer would not need to find all the URL mappings that might be reference the JSP.

In the case where a View is conditional specified in application logic, using JSP aliases avoids hard-coding JSP files in your application logic.

Figure 5.1. JSP Alias

JSP Alias