legacy-knowledge-base
公開されました Sep. 10, 2025

Freemarker templates and httpUtil errors

written-by

Jay Lee

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • When upgrading to Liferay DXP 7.4+ from 7.3 or prior versions, we have found some issues regarding httpUtil class. While the class is still available, but its methods are not.
  • An example error could be the following one:
    Error executing FreeMarker template

    freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:

    ==> httpUtil.encodePath  [in template "20155#20197#17104569" at line 19, column 28]

Environment

  • Liferay DXP 7.4+

Resolution

  • The errors that you have encountered are due to those methods have been moved to the com.liferay.portal.kernel.util.HttpComponentsUtil class in LPS-150185 (7.4 U22).
  • Therefore, using the encodePath method as an example, you should update your code to call HttpComponentsUtil.encodePath() instead of HttpUtil.encodePath().

Use in FreeMarker

  • Regarding the use of the FreeMarker template, you should be able to use staticUtil to reference the HttpComponentsUtil.
  • For example, you can assign a variable named "httpComponentsUtil" as follows:
    <#assign httpComponentsUtil = staticUtil["com.liferay.portal.kernel.util.HttpComponentsUtil"] />
    You can then use it to reference the encodePath method later in the template, e.g.:
    ${httpComponentsUtil.encodePath(path)}
  • However, keep in mind that staticUtil is a restricted variable by default and you'll need to unrestrict it in order to use it in a FreeMarker template.
    This can be accomplished via the following steps:
    1. Navigate to Control Panel > System Settings > Template Engine.
    2. Remove the text box that says "staticUtil" from "Restricted Variables" by pressing the - button.
    3. Save.
    4. Restart Liferay, this is necessary for the configuration change to take effect.

Additional Information

did-this-article-resolve-your-issue

legacy-knowledge-base